Using JavaScript

JavaScript can easily be incorporated into web page using a script tag or the onload function.

JavaScript Script Tag


Using Site Builder software Site Code when an Item is edited a script tag is available above the Content text area. This provides the following code:

< script type="text/javascript" src="">< /script>

The scr value is the source of an external javascript file. When the Item loads the source JavaScript will be included.

The script tag can also be used to embed javascript directly into the page. This method is often used to include sponsored and promotional links within a web page. For example:




The code for these types of script are usually provided by the sponsor (in this case Google) and are in the form

< script type="text/javascript">some sponsor JavaScript code< /script>

To maintain the validity of your Site Code when using sponsor generated JavaScript check that all tags provided are valid ie all tag names should be lower case and all single tags must end with />. Any comment marks <!-- and // --> should be removed and make sure there are no line breaks within the script.

JavaScript Onload


The Site Code includes two variables that allow an external JavaScript file to be embedded into the header of the site web pages and run an onload JavaScript function once the body has loaded. When provided the $scriptFile value defines the JavaScript file to be included within the header of the site pages. Once the web page has been fully loaded (displayed) the $onloadFunction function is called, when this function is called the Item Title is passed to it.

The standard $scriptFile value is script.js and a JavaScript file of this name is included when Site Builder Software is downloaded. The script.js file includes a JavaScript function itemLoaded. The standard $onloadFunction value is itemLoaded. To use this feature add any desired JavaScript functions to the script.js file. Then in the script.js file adjust the itemLoaded function to run the specific functions based on the Item title. This allows individual Items to initiate specific JavaScript functions as required. The script.js file can be edited in a text editor and must be uploaded to the same directory as the base Site Code file.





Sign In