[英]Stop navigation AFTER link has been clicked
preventDefault()
) preventDefault()
) 現在,當我單擊一個活動鏈接后單擊另一個非活動鏈接時,瀏覽器仍會轉到該活動鏈接的URL。
因此,問題是:在按下鏈接后 ,如何中止/停止/取消鏈接導航? IE瀏覽器已經可以使用了。
問題不在於:如果單擊鏈接,如何防止鏈接被跟蹤?
jQuery('a.button').on('click', function(e){
if ( jQuery(this).hasClass('active') ) {
// no preventDefault(), so link is followed
return;
}
e.preventDefault();
// how can I stop the link from above?
// ..
jQuery(this).addClass('active')
// do the slide thing
});
聽起來您想要做的是window.stop()
。
https://developer.mozilla.org/zh-CN/docs/Web/API/Window/stop
stop()方法與單擊瀏覽器中的停止按鈕完全等效。 由於腳本的加載順序,stop()方法無法停止包含該腳本的文檔的加載,但是它將停止加載大圖像,新窗口以及其他推遲加載的對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.