June 29, 2007

Adding a reference to external .js file in your form

This code creates a new script element and inserts it into the head of the HTML document that defines the form:

st = document.createElement("<script src='http://<server>/<site>/<filename>.js' language='JavaScript'>");
h = document.getElementsByTagName('head');
h[0].insertAdjacentElement('beforeEnd',st);

Using this method to reference an external script in a production environment is unsupported because it introduces several areas for concern:

  • Transportability
  • External Site
  • Doesn't work offline
  • Future Upgrade issues
  • Possible Timing issues
  • Poor programming practice

No comments: