www.webdeveloper.com
Results 1 to 2 of 2

Thread: document.write stops the browser

  1. #1
    Join Date
    Aug 2009
    Posts
    38

    document.write stops the browser

    Hi
    What is the problem in this script:

    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var destination="textDestination";
    var index=0;
    function showText(){
    if (document.getElementById){
    var dest=document.getElementById(destination);
    if (dest){ // && dest.innerHTML)
    if (index>3){
    index=0;
    }

    // part 1 (workes fine if I remove 'part 2', but stops at 'index:1' if I don't remove 'part 2')
    alert('index: '+index);

    // part 2 (makes webbrowser to stop the script for 'index:1')
    document.open();
    document.write('index: '+index);
    document.close();

    index++;
    setTimeout("showText()", 5000);
    }
    }
    }
    //-->
    </SCRIPT>

    </head>
    <body>
    <DIV ID="textDestination" style="border:3px coral solid; height=400px;">
    </DIV>
    </body>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    showText();
    //-->
    </script>
    </html>

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,373
    document.write clears the page after the page has been initially rendered.
    Therefore, the setTimeout function will erase the earlier contents of the page the first time it executes.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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



Recent Articles