如何只打开1次新标签? [英] How to open new tab only 1 time?
本文介绍了如何只打开1次新标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<script>
$(document).click(function() {
window.open("http://google.com", "_blank");
});
</script>
使用上面的代码,当我单击任意位置时,选项卡将打开.但是,当我单击更多时,将打开新选项卡.那么,如何在单击1次后禁用上述代码?
With above code, when I click anywhere, the tab will be opened. However, when I click more, the new tab will be opened. So, how to disable above code after click 1 time ?
推荐答案
使用jquery .one()
http://api.jquery.com/one/
Use jquery .one()
http://api.jquery.com/one/
<script>
$(document).one("click",function() { window.open("http://google.com", "_blank");});
</script>
这篇关于如何只打开1次新标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文