none
setInterval method not working in internet explorer

    Question

  • Given below script is working fine on Chrome browser but not working on Internet Explorer. Any advise.

    <script type="text/javascript">
    
            function msg() 
            {
                document.writeln("hello world <br>");           
            }
    
            setInterval("msg();", 3000);        
        
        </script>



    Monday, September 05, 2011 3:26 PM

All replies

  • <script type="text/javascript">
            function msg() 
            {
                document.writeln("hello world <br>");
                document.end(); // you missed this line
            }
            setInterval("msg();", 3000);        
    </script>
    

    Tuesday, September 06, 2011 2:03 AM
  • thanks for reply. but still code is unable to run in internet explorer.
    Tuesday, September 06, 2011 5:04 AM
  • Which version of IE you're using? The code that I posted runs fine in IE8.

    Note that since the setInterval() call is not linked to user action, there will be a notification bar asking whether you want this script or ActiveX control to be run. You have to "Allow blocked content" to continue.

    Btw, here's the code I used to test:

    <html>
    <head>
    <title>Testing</title>
    </head>
    <body>
    <script type="text/javascript">
            function msg() 
            {
    			document.writeln("hello world <br>");
    			document.end();
            }
            setInterval("msg();", 3000);        
    </script>
    </body>
    </html>
    

    • Edited by cheong00 Tuesday, September 06, 2011 5:34 AM
    Tuesday, September 06, 2011 5:32 AM
  • I am using IE7.

    suprisingly when i run the same code on Google Chrome its working fine there.

    Tuesday, September 06, 2011 6:31 AM
  • I think I can't help you then... This piece of HTML executes correctly even if I use development toolbar to force it render in IE7 Standard mode. :(

    EDIT: You may want to try disable all your browser addon to see if it works or not.

    • Edited by cheong00 Tuesday, September 06, 2011 8:47 AM
    Tuesday, September 06, 2011 8:46 AM
  • hey cheong00

    i'm cliffort

    i'm in the same situation as aisha i've done everything that u recommended on the previous threads the difference with me is i'm using ie with xp but i followed your thread to ensure i don't leave anything out, but it gives the same results. what do you reccomend i do?


    • Edited by cliffort Wednesday, September 14, 2011 3:40 PM
    Wednesday, September 14, 2011 3:37 PM
  • Since all of my machines are running either IE8 or IE9, and both of the browsers executes the code correctly, I think I'm unable to help. (I must be able to reproduce the problem in order to find way to resolve it, right?)
    Thursday, September 15, 2011 12:55 AM
  • Given below script is working fine on Chrome browser but not working on Internet Explorer. Any advise.

    <script type="text/javascript">

    function msg()
    {
    document.writeln("hello world <br>");
    }

    setInterval("msg();", 3000);

    </script>


    use this:

     setInterval(function(){msg()}, 3000);   

    • Proposed as answer by Ehsan Mokhtari Tuesday, October 04, 2011 6:18 AM
    Sunday, October 02, 2011 4:02 PM