1

I started a new custom template for safari in dashcode ("This template creates a blank web application, ready for customizing."). It auto generates a function load in main.js that is called from the body in index.html:

function load() {
    dashcode.setupParts();
}

I added some JS code after the function which seems to execute as part of the HEAD when i run. I also added an onclick event in the body of index.html:

<body onload="load()";>
<input type="button" onclick="sayHello()" value="Say Hello" />
</body>

I also got the the button for it when I run.

Whenever I add a document.write call to the function load (which should just execute on load before the button is displayed) nothing else gets generated when I run. In other words whenever load becomes:

function load() {
    dashcode.setupParts();
    document.write("LOADING");
}

none of the javascript that i added after the function gets displayed. Also the onclick button that i added in the body doesn't appear.

Does anybody have an explanation for this behavior?

1 Answers1

0

calling document.write() after page load will overwrite the current page - javascript, html, everything - which is why it is so frowned upon generally. Look at DOM methods or innerHTML manipulation for alternatives.

lucas
  • 1,485
  • 13
  • 22
  • Thank you for the feedback. It is also causing the onclick button that is created afterwards in the body to stop getting generated. Does document.write also cause any further processing in the body to stop? – code master Jan 17 '16 at 19:13