SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot janislanka's Avatar
    Join Date
    Sep 2004
    Location
    Lithuania
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy how to temporarly stop JS function

    I have a "gallery" where page is going to next page after 7 sec. But we want to add a button "Stop" that would stop "delayer" function. Since I'm not JS programmer, I have no idea how to do it and I beg for your help!

    This is the code:
    Code:
    <script type="text/javascript">
    <!--
    function delayer(){
        window.location = "/voorna/6.html"
    }
    //-->
    </script>
    
    <body onLoad="setTimeout('delayer()', 7000)">
    here is live example: http://autokrassen.nl/voorna/

  2. #2
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your 'delayer' function, add a check for a boolean value. If it's true, do the 'next page' thing. If it's false, the page stays where it's at.

    Use the button to toggle the value of the boolean:
    Code:
    var flag = true;
    function delayer() {
      if(flag) {
        window.location...
      }
    }
    <button onclick='flag=false;'>Stay on this page</button>

  3. #3
    SitePoint Zealot janislanka's Avatar
    Join Date
    Sep 2004
    Location
    Lithuania
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks! works great!


Bookmarks

Posting Permissions

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