View.insertJavaScript()
Overview
Inserts a JavaScript script object from a resource file into a specific Web screen or all Web screens from the host. The JavaScript file must be in the resource bundle.
This option is only available for Web hosts.
Use case
Your site was not initially designed to accommodate mobile device screens and requires additional JavaScript to display properly.
Format
View.insertJavaScript(resourceName, tag, position,
{'MATCH-URL':urlfrag, 'MATCH-SOURCE':searchText});
Parameter | Description | Type | Required | Notes |
---|---|---|---|---|
resourceName | The name of the JavaScript file in the resource bundle. | Text | Required | Do not specify a path, just the file name. For example:'special.js ' |
tag | Specifies the name of the tag where the JavaScript will be inserted. | Text | Required | Valid values: "HEAD" - Specifies that the code should be inserted between the <head></head> tags of the page. "BODY" - Specifies that the code should be inserted between the <body></body> tags of the page. |
position | Specifies where in the tag that the JavaScript will be inserted. | Text | Required | Valid values: "TOP" - Specifies that the code should be inserted at the top of the specified tag. "BOTTOM" - Specifies that the code should be inserted at the bottom of specified tag. |
urlfrag | Specifies the partial or full URL of the page where you want to insert the JavaScript. For example:'page2.html ''company/page2.html ' |
String | Optional | Part of the matching parameters object. It must be in the following format, enclosed in braces:{'MATCH-URL':'URL'} The URL must match at least a portion of the host profile address. If you want the JavaScript to be added to all pages, do not use the matching parameters object. |
searchText | Specifies a text string that must match text on the page. | String | Optional | Part of the matching parameters object. It must be in the following format, enclosed in braces:{'MATCH-SOURCE':'TEXT'} The text must be matched exactly, or the JavaScript is not inserted. It is case-sensitive. If you want the JavaScript to be added to all pages, do not use the matching parameters object. |
Example
Copy
/* Insert all scripts from javascript.js at the TOP of the
* HEAD tag and apply it only to the page2.html screen.
*/
View.insertJavaScript('javascript.js', 'HEAD', 'TOP',
{'MATCH-URL':'page2.html'});