简体   繁体   English

单击链接后停止导航

[英]Stop navigation AFTER link has been clicked

  • I have a slider with some buttons (which are links). 我有一个带有一些按钮(即链接)的滑块。
  • The buttons have double function 按钮具有双重功能
  • If I click on an inactive button, the slider will slide to the appropriate slide and the button will turn active (so preventDefault() here) 如果单击一个不活动的按钮,则滑块将滑动到相应的幻灯片,并且该按钮将变为活动状态(因此,此处为preventDefault()
  • If I click on an active button, the link will work (no preventDefault() ) 如果我单击活动按钮,则该链接将起作用(没有preventDefault()

Now, when I click on another inactive link after an active link is clicked, the browser will still got to the active link's url. 现在,当我单击一个活动链接后单击另一个非活动链接时,浏览器仍会转到该活动链接的URL。

So the question is: How can I abort/stop/cancel a link navigation, after the link was pressed? 因此,问题是:在按下链接 ,如何中止/停止/取消链接导航? IE my browser is already working. IE浏览器已经可以使用了。
The question is not : How can I prevent the link to be followed, if I click on the link? 问题在于:如果单击链接,如何防止链接被跟踪?


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
});

Sounds like what you're trying to do is window.stop() . 听起来您想要做的是window.stop()

https://developer.mozilla.org/en-US/docs/Web/API/Window/stop https://developer.mozilla.org/zh-CN/docs/Web/API/Window/stop

The stop() method is exactly equivalent to clicking the stop button in the browser. stop()方法与单击浏览器中的停止按钮完全等效。 Because of the order in which scripts are loaded, the stop() method cannot stop the document in which it is contained from loading, but it will stop the loading of large images, new windows, and other objects whose loading is deferred. 由于脚本的加载顺序,stop()方法无法停止包含该脚本的文档的加载,但是它将停止加载大图像,新窗口以及其他推迟加载的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM