如何使用 JavaScript 或 jQuery 在新选项卡中打开 URL? [英] How to open a URL in a new Tab using JavaScript or jQuery?

查看:42
本文介绍了如何使用 JavaScript 或 jQuery 在新选项卡中打开 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式在新标签页而不是新窗口中打开 URL?

How to open a URL in new tab instead of new window programatically?

推荐答案

使用 window.open():

var win = window.open('http://stackoverflow.com/', '_blank');
if (win) {
    //Browser has allowed it to be opened
    win.focus();
} else {
    //Browser has blocked it
    alert('Please allow popups for this website');
}

根据浏览器的实现,这会起作用

Depending on the browsers implementation this will work

您无法在窗口而不是选项卡中打开它.

There is nothing you can do to make it open in a window rather than a tab.

这篇关于如何使用 JavaScript 或 jQuery 在新选项卡中打开 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆