Forum Discussion
TNY_122436
Nimbostratus
Jun 19, 2013Javascript insert to HTML
Hello all,
Is it possible to insert a small piece of Javascript into HTML when traffic passes through the LTM into a certain virtual server? So one of our 3rd party vendor we use for monitoring...
Kevin_Stewart
Employee
Jun 19, 2013There's several ways to do this, but I prefer a STREAM profile for its simplicity, flexibility, and speed. To make it work, apply a generic STREAM profile to your virtual server and this iRule:
when HTTP_REQUEST {
Disable the stream filter for all requests
STREAM::disable
LTM does not decompress response content, so if the server has compression enabled
and it cannot be disabled on the server, we can prevent the server from sending
a compressed response by removing the compression offerings from the client
HTTP::header remove "Accept-Encoding"
}
when HTTP_RESPONSE {
Check if response type is text
if { [HTTP::header value Content-Type] contains "text" } {
Define the stream replacement
STREAM::expression {@@@}
Enable the stream filter for this response only
STREAM::enable
}
}
In this example I'm replacing the end body tag with a piece of JavaScript code and another end body tag. Placing the JavaScript at the bottom of the page has roughly the same effect as an onload statement in the beginning body tag, plus it's easier to manipulate. You could, alternatively, replace the end head tag with a JavaScript function and another end head tag, then replace the beginning body tag with one that has an onload statement.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects