Difference between revisions of "Adding JavaScript JS files to Web Page View Pages"

From SmartWiki
Jump to: navigation, search
(Created page with 'To include JavaScript JS files in a Web Page View custom field you must utilize the following method. <pre> <script language="JavaScript"> function include_dom(script_file…')
 
Line 1: Line 1:
 
To include JavaScript JS files in a [[Web Page View]] custom field you must utilize the following method.
 
To include JavaScript JS files in a [[Web Page View]] custom field you must utilize the following method.
 
 
  
 
<pre>
 
<pre>
Line 23: Line 21:
 
You will also have to call the ''includejsfiles'' function in the body onload:
 
You will also have to call the ''includejsfiles'' function in the body onload:
 
  <body onload="includejsfiles();">
 
  <body onload="includejsfiles();">
 +
 +
 +
===Explanation===
 +
Including the JS files within a script tag such as will cause the page to crash in certain browsers, particularly Internet Explorer.
 +
<SCRIPT type="text/javascript" language=JavaScript src="/validate.js"></SCRIPT>
 +
This method can be used in [[Browser Script]] custom fields or on template pages, sign-up pages etc. The '''includejsfiles''' method above must be used for Web Page Views.
  
  
 
[[Category:JavaScript]]
 
[[Category:JavaScript]]

Revision as of 10:01, 19 September 2011

To include JavaScript JS files in a Web Page View custom field you must utilize the following method.

<script language="JavaScript">
function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}
function includejsfiles() {
  include_dom("/validate.js");
  include_dom("/anotherfile.js");
}
</script>

You will also have to call the includejsfiles function in the body onload:

<body onload="includejsfiles();">


Explanation

Including the JS files within a script tag such as will cause the page to crash in certain browsers, particularly Internet Explorer.

<SCRIPT type="text/javascript" language=JavaScript src="/validate.js"></SCRIPT>

This method can be used in Browser Script custom fields or on template pages, sign-up pages etc. The includejsfiles method above must be used for Web Page Views.