2

I need to open multiple urls on click of a button. Am testing on Chrome PS: I am doing this for myself. I am just trying to open all urls which i want to read daily in the morning. I don't want to waste time clicking on each url for example. Not sure if javascript is the right tool to build such functionality or not Wrote the following code and it's not opening, just opening the first and the last url

<html>
    <head>
        <title>Shopping</title>
        <script>               

            function Software()
            {
                window.open("http://forums.asp.net/", "status=1,toolbar=1,menubar=1");
                window.open("http://www.joelonsoftware.com/", "status=1,toolbar=1,menubar=1");
                window.open("http://blog.cwa.me.uk/", "status=1,toolbar=1,menubar=1");
                window.open("http://www.lifehacker.com/", "status=1,toolbar=1,menubar=1");
                window.open("http://www.Theverge.com", "status=1,toolbar=1,menubar=1");
                window.open("http://www.hanselman.com/", "status=1,toolbar=1,menubar=1");
                window.open("http://www.goodreads.com", "status=1,toolbar=1,menubar=1");
                window.open("http://www.stackoverflow.com", "status=1,toolbar=1,menubar=1");
            }

        </script>
    </head>
    <body>            
        <a href="http://www.channel9.msdn.com/" onclick="Software()">
            Software / Programming 
        </a>
    </body>
</html>
Charu
  • 2,679
  • 6
  • 35
  • 52
  • 2
    What browser do you use? Some browser may block pop-ups. – Kiril Feb 06 '14 at 16:07
  • @Kiril Testing on Chrome. – Charu Feb 06 '14 at 16:08
  • 1
    I would say 90% of modern browsers will block this. Opening so many windows to different URLs is only going to look suspicious (and to be honest it is suspicious). You also have no control over when the browser will prevent this. Put simply, **don't do this**. No body ever likes this functionality – Liam Feb 06 '14 at 16:11
  • 1
    Most browsers are trying to prevent this sort of behavior because of misuse. – jfriend00 Feb 06 '14 at 16:11
  • possible duplicate of [Allow window.open to open new window and not popup](http://stackoverflow.com/questions/14643040/allow-window-open-to-open-new-window-and-not-popup) – Liam Feb 06 '14 at 16:11
  • @Liam is right, it's not a good practice. It could be done with the help of adding `"_black"` as a second parameter but chrome will block 7 of 8 pop-ups. – Kiril Feb 06 '14 at 16:15
  • Would the browser still block these if there was a timeout before each one? – Craighead Feb 06 '14 at 16:20
  • @jfriend00 I am doing this for myself. I am just trying to open all urls which i want to read daily in the morning. I don't want to waste time clicking on each url for example. Not sure if javascript is the right tool to build such functionality or not – Charu Feb 06 '14 at 16:40

3 Answers3

4

Give your windows unique names:

function Software() {
  window.open("http://forums.asp.net/", "w1", "status=1,toolbar=1,menubar=1");
  window.open("http://www.joelonsoftware.com/", "w2", "status=1,toolbar=1,menubar=1");
  window.open("http://blog.cwa.me.uk/", "w3", "status=1,toolbar=1,menubar=1");
  window.open("http://www.lifehacker.com/", "w4", "status=1,toolbar=1,menubar=1");
  window.open("http://www.Theverge.com", "w5", "status=1,toolbar=1,menubar=1");
  window.open("http://www.hanselman.com/", "w6", "status=1,toolbar=1,menubar=1");
  window.open("http://www.goodreads.com", "w7", "status=1,toolbar=1,menubar=1");
  window.open("http://www.stackoverflow.com", "w8", "status=1,toolbar=1,menubar=1");
}

Note that these links will open as actual windows, not tabs.

Demo: http://jsfiddle.net/9xBv7/

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136
  • I can see only the first url being opened in the demo – Charu Feb 06 '14 at 16:57
  • Multiple windows are open on top of each other - move the top window, you will see the rest – Yuriy Galanter Feb 06 '14 at 16:59
  • This triggers the default popup blocker in chrome so that only the first URL opens in a new window. All other URLs are not opened and are listed as being blocked from opening the popup blocker's UI. – ckittel Jun 24 '15 at 18:57
2

If you're doing this for yourself, Chrome has a feature when you right click on a folder of bookmarks that offers you the choice to "Open All Bookmarks In a New Window".

The other options that might avoid the popup blocker logic are to write a small browser plugin or to use the command line to start an instance of the browser with a bunch of URLs.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
0

You might want to try just setting your home page to open all those when your browser opens instead.

Link

Or you could embed them in IFrames in a page as well. That way you don't have to open a bunch of different windows.

nobody
  • 7,803
  • 11
  • 56
  • 91