14

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
Community
  • 1
  • 1
Abhishek
  • 6,526
  • 13
  • 53
  • 83

6 Answers6

14

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;
Federico Saenz
  • 462
  • 1
  • 5
  • 20
2

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

window.addEventListener("beforeunload", function(e){
    yourCustomFunction();
});
Kos
  • 4,483
  • 8
  • 35
  • 39
Bowen Li
  • 367
  • 1
  • 8
1

Set it to an empty function:

window.onbeforeunload = () => {}

Kos
  • 4,483
  • 8
  • 35
  • 39
Marian Zburlea
  • 8,631
  • 4
  • 30
  • 37
0

Enclose your form tag inside div like this:

<div class="col-xs-12 no-padding"><form role="form" class="form-horizontal pad10-top" id="" onSubmit="return false;"> ...</form></div>

Kos
  • 4,483
  • 8
  • 35
  • 39
Katta Nagarjuna
  • 1,520
  • 2
  • 12
  • 12
0

You can try this as well.

$(window).off('beforeunload');

TauFeeQ
  • 133
  • 1
  • 9
0

adding this line got me through

window.addEventListener("beforeunload", function (e) { return true; });
dersvenhesse
  • 6,015
  • 2
  • 28
  • 50
Naddy
  • 1