开发者

How can I open a new browser tab from within JavaScript?

How do I write a JavaScript function that opens a new browser tab at a specified UR开发者_StackOverflowL? I know how to do this in In HTML using a link with target="_blank", but in my case I need to do it from within the JS function.

Thanks


You can't. Javascript has no built-in support for tabs, because not all Javascript capable browser have tabs at all (think IE6). You can at most open a new window (though that might get pop-up blocked of course).

Some browsers might show those new windows as tabs. I believe Opera does this.


You cannot specify to open in a 'new tab', but if you have a tabbed browser this behavior is configurable. For example, I believe Firefox has this behavior by default

See Tools -> Options -> Tabs -> check "open new windows in a new tab instead"

The following JavaScript will work a charm for you

<script>
    window.open("http://www.google.com", "google"); 
</script>


<script>
  window.open("http://stackoverflow.com/", "SO");
</script>

More info is here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜