Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable/override "Do you want to leave this site?" alert?

I've a form in a pop-up, which is loaded by AJAX call. It is built using form_for tag of RoR. Even if I don't modify any field in it and try to navigate to another page, following alert is shown by chrome.

enter image description here

I want to disable this alert box. Is it possible? If yes, how?

I've already tried this, but it is not valid anymore.

Following are the environment settings,

Ruby version = 1.9.3
Rails version = 3.1.4
Chrome version = 52
jQuery version = 1.10.2
like image 661
Abhishek Avatar asked Aug 02 '16 14:08

Abhishek


2 Answers

Alert is displayed because somewhere on your code, you are overriding the window before unload event, and when you try to close the window, the event fires. Try disallow this event putting up this on your code:

window.onbeforeunload = null;
like image 84
Federico Saenz Avatar answered Oct 10 '22 16:10

Federico Saenz


You can hook in any other function inside the beforeunload handler:

window.addEventListener("beforeunload", function(e){
    yourCustomFunction();
});
like image 36
Bowen Li Avatar answered Oct 10 '22 17:10

Bowen Li