Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 covering the Esc button by hooking onto document.body.onkeyup, but couldn't find anything covering mouse click on the Stop button.

like image 792
Nilzor Avatar asked Oct 11 '11 15:10

Nilzor


3 Answers

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).

like image 157
Jacob Mattison Avatar answered Oct 20 '22 09:10

Jacob Mattison


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.

like image 4
Dennis Avatar answered Oct 20 '22 08:10

Dennis


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.

like image 3
namuol Avatar answered Oct 20 '22 08:10

namuol