HTML:如何强制链接在新选项卡而不是新窗口中打开
我使用 target="_blank"
在新选项卡中打开链接。但在 IE 中,它会打开一个新窗口,这是完全合乎逻辑的,因为这就是 _blank
应该做的事情。
我不知道 target="_blank"
在其他浏览器中的行为如何。
有什么可以强制链接在新选项卡中打开的吗?如果浏览器支持选项卡...否则创建一个新窗口
I use target="_blank"
to open links in a new tab. But in IE it opens a new window which is completely logical because that is what _blank
is supposed to do.
And i don't know how target="_blank"
behaves in other browsers.
Is there something to force links to open in a new tab. If the browser supports tabs... else make a new window
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
作为浏览器呈现的 HTML 的作者,没有办法做到这一点。至少据我所知还没有。这很大程度上取决于浏览器及其由用户自己设置的设置/首选项。
另外,您不应该将其强加给任何用户。浏览器是用户的财产。如果用户想要打开选项卡或新窗口中的所有链接,那么就让用户这样做。
幸好我们不能做某些事情。
target=_blank
仍然被滥用,弹出窗口已经被消灭了。There is no way to do that as the author of the HTML that a browser renders. At least not yet that I know of. Its pretty much up to the browser and its settings / preferences that are set by users themselves.
Also, you shouldn't impose this upon any user. A browser is the user's property. If a user wants to open all links in tabs or in new windows, then let the user do exactly that.
It's good that we can't do certain things.
target=_blank
is still abused and popups have been done to death.由于我陷入了这个老问题,然后发现它现在是可能的(也许这个 css 选项当时不可用),我只想添加有关如何完成它的更新:
以下是 target-new 的选项style:
没有测试none选项,可能它使用默认的浏览器设置。
我在 Firefox 和 IE7-9 上确认了这一点。
Since I fell into this old question and then found that it is now possible (maybe this css option wasn't available then), I just want to add an update on how it can be done:
Here are the options for the target-new style:
Didn't test the none option, maybe it uses the default browser setting.
I confirmed this for Firefox and IE7-9.
不,没有。
No, there isn't.
我希望这会对您有所帮助
window.open(url,'_newtab');
I hope this will help you
window.open(url,'_newtab');
我没有尝试这个,但我认为它适用于所有浏览器:
target="_parent"
I didn't try this but I think it works in all browsers:
target="_parent"
浏览器处理新窗口与新选项卡的方式在浏览器的选项中设置,并且只能由用户更改。
The way the browser handles new windows vs new tab is set in the browser's options and can only be changed by the user.
target-new 属性指定新的目标链接是否应在新窗口或现有窗口的新选项卡中打开。
注意:仅当 target-name 属性创建新选项卡或新窗口时,target-new 属性才起作用。
The target-new property specifies whether new destination links should open in a new window or in a new tab of an existing window.
Note: The target-new property only works if the target-name property creates a new tab or a new window.
您可以在 Safari > 中更改 Safari 打开新页面的方式首选项>标签> '在选项卡而不是窗口中打开页面' > '自动地'
You can change the way Safari opens a new page in Safari > Preferences > Tabs > 'Open pages in tabs instead of windows' > 'Automatically'
您可以设置 IE 在新选项卡中打开链接,只需进入设置菜单即可。
You can set IE to open links in new tab, just go to the settings menu.
在 Internet Explorer 中,单击工具 ->互联网选项。单击常规选项卡->选项卡 ->设置。选择“遇到弹出窗口时”->始终在新选项卡选项中打开弹出窗口。单击“确定”。
In Internet Explorer, click the Tools -> Internet Options. Click General tab -> Tabs -> Settings. Choose "When a pop-up is encountered"-> Always open pop up in new tab option. Click OK.
这是可能的!
这似乎会覆盖浏览器设置。希望它对你有用。
It is possible!
This appears to override browser settings. Hope it works for you.
简单地使用“target=_blank”将尊重用户/浏览器对是否使用选项卡或新窗口的偏好,这在大多数情况下是“做正确的事情”。
如果您指定新窗口的尺寸,某些浏览器将使用它作为需要特定尺寸的指示符,在这种情况下,将始终使用新窗口。 堆栈溢出代码示例 堆栈溢出
Simply using "target=_blank" will respect the user/browser preference of whether to use a tab or a new window, which in most cases is "doing the right thing".
If you specify the dimensions of the new window, some browsers will use this as an indicator that a certain size is needed, in which case a new window will always be used. Stack overflow code example Stack Overflow
尝试使用像这样的 javascript 函数
Html:
Javascript:
Try with javascript function like this
Html:
Javascript: