Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Location
    Hong Kong
    Posts
    119
    Thanks
    8
    Thanked 0 Times in 0 Posts

    window.open - can I open it with a delay?

    I do write some php, but have not much idea about JavaScript.

    I use window.open to open 10 pages simultaneously. I prefer to open them with a time delay from each other to put less load on the target server. This is my code with no delay. (I played around with setTimeout but can't get it to work.)

    PHP Code:
    <a href='http://www.".$new[9]."' 
    onclick="window.open('http://www.".$new[0]."/');
    window.open('http://www."
    .$new[1]."/'); 
    window.open('http://www."
    .$new[2]."/'); 
    window.open('http://www."
    .$new[3]."/'); 
    window.open('http://www."
    .$new[4]."/'); 
    window.open('http://www."
    .$new[5]."/'); 
    window.open('http://www."
    .$new[6]."/'); 
    window.open('http://www."
    .$new[7]."/'); 
    window.open('http://www."
    .$new[8]."/')\" target='new300/'>Open 10</a> 

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,246
    Thanks
    12
    Thanked 340 Times in 336 Posts
    I'm not sure if I, as a user of your website, would come again if a click on a link that opens 10 more pages. I'd find that highly annoying.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    Hong Kong
    Posts
    119
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    I'm not sure if I, as a user of your website, would come again if a click on a link that opens 10 more pages. I'd find that highly annoying.
    I totally agree!

    However, it's for a tool I wrote and strictly for my own use.

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,246
    Thanks
    12
    Thanked 340 Times in 336 Posts
    you'll most probably won't come around a pure JS solution (meaning no inline-JS).

    some idea
    PHP Code:
    var wop = {
      urls: [],
      start: function() {
        var urls = wop.urls.concat();
        this.href = urls.pop();
        wop.count = urls.length;
        wop.open();
      },
      open: function() {
        if (wop.count--) {
          window.open(wop.urls[wop.count]);
          window.setTimeout(wop.open, 1000);
        }
      }
    }
    <?php
      printf
    ("wop.urls = %s;"json_encode($news));
    ?>
    document.getElementById("link").addEventListener("click", wop.start, true);
    Last edited by Dormilich; 01-20-2012 at 10:43 AM.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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