www.webdeveloper.com
Results 1 to 9 of 9

Thread: clearTimeout not working as expected in ie6

  1. #1
    Join Date
    Dec 2008
    Posts
    10

    Question clearTimeout not working as expected in ie6

    Hi, just hoping someone can point me in the right direction.

    I have the code below, and clearTimeout doesn't seem to be ever called, or if it is, it doesn't have the desired effect.

    The desired effect, is that when onresize is fired, it then calls the resize function, which then executes the clearTimeout.

    I have tried using it as in the code below, and directly following the setTimeout in the functions (so instead of calling the function it just directly executes clearTimeout, and neither has had the desired effect.

    Any help would be very much appreciated.

    Code:
    <html>
    <head>
    <meta http-equiv="Page-Enter" content="RevealTrans(duration=2,transition=23)">
    <script language="JavaScript">	
    function SSS()
    {
    	var t;
    	t=setTimeout("Slide1()",3000);
    }
    function resize()
    {
    	clearTimeout(t);
    }
    function Slide1()
    {
    	var x = document.frames.MainFrame.location="lib/one.html";
    	x = null;
    	t=setTimeout("Slide2()",8000);
    }
    function Slide2()
    {
    	var x = document.frames.MainFrame.location="lib/two.html";
    	x = null;
    	t=setTimeout("Slide1()",8000);
    }
    </script>
    </head>
    <body onLoad="SSS()" onresize="resize()">
    	<iframe  id="MainFrame" Src="lib/one.html" width="100%" height="100%" frameborder="0">
    	</iframe>
    </body>
    </html>

  2. #2
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    first, the reference to the iframe window is wrong. frames generate a new separate window object. when you refer a frame by it's id you get the element, not the window object of that frames. however, there are two way you can get the window object: using the frames object or reading the object contentWindow from the iframe element. what follow is how you write it:
    Code:
    document.getElementById("MainFrame").contentWindow.location="lib/one.html";
    second, there is a chance browser throw error when resize is done before any of the slide function is called. that is because the variable t is defined as local to that function. remove the var statement in function SSS.
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

  3. #3
    Join Date
    Dec 2008
    Posts
    10
    Thank you for that. I made those changes as you suggested, and tested it.

    It still didn't have the desired effect, as when the resize occured, the slideshow stopped and never started again. But I'm pretty sure that means that the resize function was called as desired, just that it didn't then break out of the setTimeout and continue, which is the desired effect. So thank you very much for your help, seems to me that it's pretty close to working the way I want now.

    So if anyone could help with working out what other changes are needed, it would be very much appreciated.

  4. #4
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    then there is no reason to clear the timeout. just don't stop the timeout so that it continue changing the document. unless you have a reason for stopping it when resize occur.
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

  5. #5
    Join Date
    Dec 2008
    Posts
    10
    The intent is for it to 'break out' of the timeout when it detects a resize and then continue, instead of only continuing when the timeout finishes.

  6. #6
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    if i correctly understood the argument, problem is that browser don't have an event for detecting when resize is done so that you can resume the slide.
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

  7. #7
    Join Date
    Dec 2008
    Posts
    10
    Quote Originally Posted by ZeroKilled View Post
    if i correctly understood the argument, problem is that browser don't have an event for detecting when resize is done so that you can resume the slide.
    That's correct, I want it to detect when the resize event occurs and then straight away go to the next slide, which will then detect the size.

  8. #8
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    sorry to mention, but there is no such event; as far as i know. and can't think of a solution
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

  9. #9
    Join Date
    Dec 2008
    Posts
    10
    Sorry, perhaps I have not been clear enough in my explaination.

    It seems to detect the resize correctly with this piece of code:
    Code:
    <body onLoad="SSS()" onresize="resize()">
    All I need to do is get the timeout to finish early when this event occurs and then have it resume normal operation.

    I have been able to find snippits of code that do these things - detect the resize event and react, set a timeout, end the timeout early and then resume - but I'm at a loss as to why it doesn't work as I expect it to.

    Maybe the fault lays with the
    Code:
    setTimeout("Slide1()",8000);
    existing in a function and calling another function at the end of the timeout? I'll try that but it seems like a bit of a longshot to me.

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