Results 1 to 2 of 2

Thread: trouble with loading a script to a document using javascript

  1. #1
    Join Date
    Jan 2013

    trouble with loading a script to a document using javascript

    Hi I am new to javascript and having trouble with it. It only works when I use window.onload. If i try to write a script and use document.write("blahblah"); the document shows up blank. What could be the issue here?

    p.s. someone else recommended that i try using window.onload function() {document.write("blahblah")}
    and it worked but i can't write scripts normally without it.
    can someone please explain why?

  2. #2
    Join Date
    Nov 2012
    document.write is considered to be a bad practice.
    For example, when executed after the page has finished loading it will overwrite the page, or write a new page, or not work at all.
    The solution may be to use innerHTML method of a DOM element, something like this:

    <div id="block"></div>

    document.getElementById('block').innerHTML = '<b>YO</b>, that works!';


    Or DOM manipulation methods http://www.w3schools.com/dom/dom_document.asp

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center