Charu
Charu

Reputation: 2717

Trying to open multiple windows in javascript

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>

Upvotes: 3

Views: 12628

Answers (3)

Yuriy Galanter
Yuriy Galanter

Reputation: 39777

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/

Upvotes: 4

jfriend00
jfriend00

Reputation: 707986

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.

Upvotes: 2

nobody
nobody

Reputation: 8293

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.

Upvotes: 0

Related Questions