Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

trying to detect browser close event

trying to detect browser close event  using -'javascript,jquery,browser'

I have tried many methods to detect browser close event through jQuery or JavaScript. But, unfortunately, I have not been able to detect the close. The onbeforeunload and onunload methods are also not working.

How do I detect the window close, unload, or beforeunload events?

asked Oct 7, 2015 by rajeshujade
0 votes

Related Hot Questions

Government Jobs Opening

Please try this code, this is working fine for me. This custom message is coming into Chrome browser but in Mozilla this message is not showing.

answered Oct 7, 2015 by santosh soni
0 votes

Maybe it's better to use the path detecting mouse.

In BrowserClosureNotice you have a demo example and pure javascript library to do it.

It isn't perfect, but avoid problems of document or mouse events...

answered Oct 7, 2015 by shegokar.anjeet
0 votes

Following script will give message on Chrome and IE:

enter image description here

enter image description here

on Firefox you will get generic message

enter image description here

Mechanism is synchronous so no server calls to delay will work, you still can prepare a mechanism like modal window that is shown if user decides to stay on page, but no way to prevent him from leaving.

Response to question in comment

F5 will fire event again, so will Atl+F4.

answered Oct 7, 2015 by abhi
0 votes

You can try something like this.



When the user closes the window, the callback will be fired.

answered Oct 7, 2015 by bhavin