[英]Open link in new tab when user clicks
I want to create a jQuery script that opens a specific url in a new tab if the user clicks somewhere (no matter where).我想创建一个 jQuery 脚本,如果用户单击某个地方(无论在哪里),它会在新选项卡中打开特定的 url。 After that, the user should be able to click anywhere without getting a new tab at every click again.
之后,用户应该能够点击任何地方,而无需在每次点击时再次获得一个新标签。
Unfortunately I have no idea how to create such a script, and therefore I would appreciate all your answears:)不幸的是,我不知道如何创建这样的脚本,因此非常感谢您的所有回答:)
You can use the .one() event like 您可以使用.one()事件,例如
$(window).one('click', function() {
var url = "http://google.com";
window.open(url, "_blank");
})
_blank
in window.open() is used to open the link in a new tab. window.open()中的
_blank
用于在新选项卡中打开链接。
Refer to following links for documentation on .one() and window.open() 请参考以下链接以获取有关.one()和window.open()的文档
$(window).one('click', function() {
var url = "http://google.com";
window.open(url, "_blank");
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.