JQuery browser stop button event

Is there any way to detect when the user clicked the stop button in any browser? I want to stop the script from starting when the user decides to click the stop button when loading the file, so I can run the script to refresh the page.

+3
jquery
source share
1 answer

Unfortunately, the browser stop button does not affect AJAX requests. If you want to cancel the AJAX request, you can abort it as shown below:

var xhr = $.ajax( url: "http://someurl.org", success: function() { ... } ); xhr.abort(); 

The interrupt start button should be in your HTML, since the browser stop button cannot interrupt the request. If the user goes to another page, the browser will stop listening, and this happens when you call xhr.abort ().

+1
source share

All Articles