Skip to content Skip to sidebar Skip to footer

Any Javascript Event Occurring When User Clicks Stop Load Button?

I want to run some Javascript when the user clicks the Stop Load-button (red X in most browsers) or hit Esc on the keyboard, which usually does the same. I've seen questions here c

Solution 1:

Internet Explorer has a document.onstop event that is fired, but other browsers don't seem to support that. Note that it's fired when the user clicks Stop or hits Esc, OR if the user navigates to another page during page load, which has the same effect.

I don't believe there is a reliable way to trigger an event on clicking Stop in other browsers. Perhaps it would be possible to do something like: keeping the connection to the server open (as in the Comet approach), streaming some sort of keep-alive down the connection, and detecting if the stream ends (as I assume it would if the Stop button were clicked).

Solution 2:

If it's images that are still getting loaded on the page, you can use the onabort event to monitor for the stop load.

Monitoring for the mouse click should be impossible, as it doesn't happen inside the current browsing window.

Solution 3:

There isn't any cross browser way of doing this.

However, IE has a special event, onstop which occurs on the body when the stop button is pressed. You cannot override the stop button functionality (that is, you cannot cancel it), but you can detect that it has happened in IE.

Post a Comment for "Any Javascript Event Occurring When User Clicks Stop Load Button?"