Chapter 6: Definition Reference
define javascript
A javascript definition is used to define a javascript transformer, which adds javascript that you supply to HTML responses.
Syntax
define javascript transformer_id
…
end
where:
•
•A
replacement ::= << endmarker newline
This allows you to specify a block of javascript to be inserted at the beginning of the HTML page (prolog), to be inserted at the end of the HMTL page (epilog), and to be executed when parsing is complete and the page is loaded (onload). Each of the section types is optional.
Layer and Transaction Notes
Applies to proxy transactions.
Example
The following is an example of a javascript transformer that adds a message to the top of each Web page, used as part of a simple content filtering application:
define javascript js_transformer onload <<EOS
var msg = "This site is restricted. Your access has been logged."; var p = document.createElement("p"); p.appendChild(document.createTextNode(msg)); document.body.insertBefore(p, document.body.firstChild);
EOS end
define action js_action transform js_transformer
end
<proxy>
category=restricted action.js_action(yes)
The VPM uses javascript transformers to implement popup ad blocking.
255