tags:

views:

296

answers:

4

I want to stop the browser request, when user clicks on any button from UI, like stop button on browser. I want to do it through javascript.

A: 

The only way would be to change the window.location to point to another URL

window.location="http://mysite.com/you_have_stopped.html";

Then you can direct the user to a page will tells them the action has stopped. Alternatively, trigger a reload

window.location.reload()

There is no way to trigger the browser stop buttom from JS.

However, if you've made the request using an XMLHttpRequest object, you can use the abort() method to abandon it.

Paul Dixon
+2  A: 

You can try a few things .. I looked at a forum here

followings from that ..

In Netscape, window.stop() seems to work (in the same way as the Stop button on the browser I guess). However, this does not work in IE.

I don't think you can stop the processing in IE, but you might try one of the following:

Event.cancelBubble this is IE only and stops EVENT propogation. However, once the event has occurred (onSubmit, onClick or whatever you used to start the download), I'm not sure this will stop it.

Event.reason IE only. Reason holds the value of the code specifying the status of the data transfer. 0=successful, 1=aborted, 2=error. I don't remember if this is readonly. If it is not, perhaps you can assign a value of 1 to abort the transfer.

Event.returnValue IE only. I'll quote this one. 'If returnValue is set, its value takes precedent over the value actually received by an event handler. Set this property to false to cancel the default action fo the sourece element on which the event occured.'

Play with these a bit. I don't see anything else that might work. If they don't do anything to stop the process, it probably can't be done.

I found a way to do this after a lot of research - use

document.execCommand("Stop");

This works in IE.

Wbdvlpr
A: 

Please use below code for cross browsers solution. I tried it with FF3.5.2, Safari 3.1 and IE 7 and 8 its working fine

if(navigator.appName == "Microsoft Internet Explorer") { window.document.execCommand('Stop'); } else { window.stop(); }