最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Trying to open multiple windows in javascript - Stack Overflow

programmeradmin3浏览0评论

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("/", "status=1,toolbar=1,menubar=1");
                window.open("/", "status=1,toolbar=1,menubar=1");
                window.open("/", "status=1,toolbar=1,menubar=1");
                window.open("/", "status=1,toolbar=1,menubar=1");
                window.open("", "status=1,toolbar=1,menubar=1");
                window.open("/", "status=1,toolbar=1,menubar=1");
                window.open("", "status=1,toolbar=1,menubar=1");
                window.open("", "status=1,toolbar=1,menubar=1");
            }

        </script>
    </head>
    <body>            
        <a href="/" onclick="Software()">
            Software / Programming 
        </a>
    </body>
</html>

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/", "status=1,toolbar=1,menubar=1");
                window.open("http://www.joelonsoftware./", "status=1,toolbar=1,menubar=1");
                window.open("http://blog.cwa.me.uk/", "status=1,toolbar=1,menubar=1");
                window.open("http://www.lifehacker./", "status=1,toolbar=1,menubar=1");
                window.open("http://www.Theverge.", "status=1,toolbar=1,menubar=1");
                window.open("http://www.hanselman./", "status=1,toolbar=1,menubar=1");
                window.open("http://www.goodreads.", "status=1,toolbar=1,menubar=1");
                window.open("http://www.stackoverflow.", "status=1,toolbar=1,menubar=1");
            }

        </script>
    </head>
    <body>            
        <a href="http://www.channel9.msdn./" onclick="Software()">
            Software / Programming 
        </a>
    </body>
</html>
Share Improve this question edited Feb 6, 2014 at 16:40 Charu asked Feb 6, 2014 at 16:06 CharuCharu 2,7276 gold badges36 silver badges53 bronze badges 8
  • 2 What browser do you use? Some browser may block pop-ups. – Kiril Commented Feb 6, 2014 at 16:07
  • @Kiril Testing on Chrome. – Charu Commented Feb 6, 2014 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 Commented Feb 6, 2014 at 16:11
  • 1 Most browsers are trying to prevent this sort of behavior because of misuse. – jfriend00 Commented Feb 6, 2014 at 16:11
  • possible duplicate of Allow window.open to open new window and not popup – Liam Commented Feb 6, 2014 at 16:11
 |  Show 3 more ments

3 Answers 3

Reset to default 4

Give your windows unique names:

function Software() {
  window.open("http://forums.asp/", "w1", "status=1,toolbar=1,menubar=1");
  window.open("http://www.joelonsoftware./", "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./", "w4", "status=1,toolbar=1,menubar=1");
  window.open("http://www.Theverge.", "w5", "status=1,toolbar=1,menubar=1");
  window.open("http://www.hanselman./", "w6", "status=1,toolbar=1,menubar=1");
  window.open("http://www.goodreads.", "w7", "status=1,toolbar=1,menubar=1");
  window.open("http://www.stackoverflow.", "w8", "status=1,toolbar=1,menubar=1");
}

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

Demo: http://jsfiddle/9xBv7/

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 mand line to start an instance of the browser with a bunch of URLs.

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.

发布评论

评论列表(0)

  1. 暂无评论