2014-12-25 39 views
0
<script> 
$(document).click(function() { 
    window.open("http://google.com", "_blank"); 
}); 
</script> 

使用上面的代碼,當我點擊任何地方,該標籤將被打開。但是,當我點擊更多時,新標籤將打開。那麼,如何在點擊1次後禁用上述代碼?如何只打開一個新標籤頁1次?

回答

2

使用jQuery .one()http://api.jquery.com/one/

<script> 
$(document).one("click",function() { window.open("http://google.com", "_blank");}); 
</script> 
+0

或者說,取決於什麼是想要的,比的名字'_blank'其他窗口的東西。 –

相關問題