Results 1 to 2 of 2

Thread: Javascript: Wait until page loads instead of timer.

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked
    0 times in 0 posts

    Javascript: Wait until page loads instead of timer.

    Ive got the following script in my page, it switches page every 10 seconds which works well however I would prefer it to wait until the page it load up is completed before moving onto the next link because some people who use it are finding the pages aren't loading completely before it switches. Anyone know if its a simple change from 10000 to a different variable? Im just drawing a blank.

    <script type="text/javascript">

    var win = null;
    var i = 0;
    var links = [
    <!--Link 1-->
    "url",
    <!--Link 2-->
    "url",
    <!--Link 3-->
    "url",
    <!--Link 4-->
    "url"
    ];


    function cranking(idx) {
    if(!win){
    win = window.open();
    };

    win.location.href = (links[idx]);

    if(idx < (links.length - 1)) {
    idx++;
    setTimeout('cranking(' + idx + ')', 10000);
    //or setTimeout('cranking(idx)', 10000);
    };
    };
    </script>

  2. #2
    Senior Moment blueball's Avatar
    Join Date
    Aug 2005
    Location
    Edinburgh
    Posts
    2,426
    Thanks
    846
    Thanked
    379 times in 294 posts
    • blueball's system
      • Motherboard:
      • Asus Z390A
      • CPU:
      • i9-9900KS
      • Memory:
      • Kingston 64GB (2x32GB) DDR4 2400MHz
      • Storage:
      • 2TB Samsung 970 EVO Plus NVMe PCIE M.2 plus Samsung 860 EVO 4TB SSD
      • Graphics card(s):
      • ASUS TUF RTX 3080 Ti GAMING OC
      • PSU:
      • Corsair HX850 850 W Full Modular 80 Plus Platinum
      • Case:
      • Corsair Carbide 330R Ultra Silent Midi Tower
      • Operating System:
      • Win 10 Pro x64
      • Monitor(s):
      • IIYAMA 3461WQ IPS 34" 3440x1440 plus BenQ GW2765HT IPS 27" 2560x1440
      • Internet:
      • Plusnet 28Mb

    Re: Javascript: Wait until page loads instead of timer.

    Could you play with this code to help? ie check to see if page has loaded before running script

    http://stackoverflow.com/questions/9...ie-7-firefox-3
    Rgds,

    BB
    Hexus Trust here and here

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
  •