简体   繁体   中英

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)
  • If I click on an active button, the link will work (no 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.

So the question is: How can I abort/stop/cancel a link navigation, after the link was pressed? IE my browser is already working.
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() .

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

The stop() method is exactly equivalent to clicking the stop button in the browser. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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