Web Analytics Made Easy -
StatCounter dynamically writing html AND JAVASCRIPT - CodingForum

Announcement

Collapse
No announcement yet.

dynamically writing html AND JAVASCRIPT

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • dynamically writing html AND JAVASCRIPT

    I use document.write() to output a whole document including <HTML><LINK for CSS><HEAD><BODY><FORM> tags etc.

    The page displays correctly.

    I then wish to include some js functions in the <HEAD> using document.write,
    eg line1: document.write('<SCRIPT language="JavaScript">');
    eg line2: document.write('alert("testing");'); etc etc
    however it fails.

    If you write an entire page with document.write how then do you include further javascript in the document for handling form events etc.

    Any assistance will be greatly appreciated.

  • #2
    the answer with thanks to a prior post by glenngv

    function includeJS(jsPath){
    var js = document.createElement("script");
    js.setAttribute("type", "text/javascript");
    js.setAttribute("src", jsPath);
    document.getElementsByTagName("head")[0].appendChild(js);
    }

    includeJS("/js/firstExternalJs.js");
    includeJS("/js/secondExternalJs.js");

    Comment

    Working...
    X