简体   繁体   中英

How can I open several tabs in a one new browser window?

I'm trying to create a web page that opens two separate browser tabs in the same window. However, using window.open appears to open two separate windows, instead of two browser tabs within the same new window.

I attempted to open http://en.wikipedia.org and http://jsfiddle.net in the same browser window, but each tab was opened in a separate window instead:

window.open("http://www.jsfiddle.net/", "newWindow", "height=200,width=200");
window.open("http://en.wikipedia.org/", "newWindow", "height=200,width=200");

What am I doing wrong here , and what is the correct way to open multiple tabs in a single new window using JavaScript?

它取决于通常是用户首选项一部分的浏览器设置,并且没有特定的技巧可以强制浏览器以某种方式运行!

Try with this lines, it should work.

    <a class="link1">Link 1</a>
    <a class="link2">Link 2</a>
      <script  type="text/javascript">
            $("a.link1").on("click",function(){
               window.open('http://www.jsfiddle.net/','_blank');
            });
            $("a.link2").on("click",function(){
               window.open('http://en.wikipedia.org/','_blank');
            });
      </script>

I think the ablove lines of code may not work in all the browsers, we can do it in other way by setting the target value for the anchor tag as follows.

$('a').click(function() {
  $(this).attr('target', '_blank');
});

Opening a webpage URL in window or tab depends on user's preferences in browser settings. Modern browsers do not allow a web application or webpage to change this behavior. But you can create a browser add-on or extension to override user's browser settings and can open a page in a tab or window using the extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM