How can I disable "Are you sure you want to leave this page" popups in Chrome?

22

1

Is there a way to disable the Are you sure you want to leave this page? message on a website? I'm using Chrome.

user204672

Posted 2013-12-09T08:52:44.650

Reputation:

Answers

8

Those messages are implemented by website developers by listening to the onunload or onbeforeunload events.

There is a userscript available from about.com that blocks those events.

In order to install this userscript (or other userscripts, for that sake) you need to first install a Chrome extension called TamperMonkey.

Be careful when installing userscripts, they are capable of doing things you might not want. Only install userscripts from trusted sources.

Vidar Ramdal

Posted 2013-12-09T08:52:44.650

Reputation: 311

it is no longer useful.. – pjpj – 2018-08-03T10:54:39.297

this solution don't work – Argus – 2019-12-10T14:35:05.787

3

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

This is worked for me.

Ashwini K R

Posted 2013-12-09T08:52:44.650

Reputation: 41

4A bit more detail on your proposed solution would help – Dave M – 2017-08-09T12:08:26.790

poor description. typed this in console but no result. don't work for me. – Argus – 2020-01-30T07:14:58.370

1

Using jQuery

$(window).off('beforeunload'); // tested in IE 11 and Chrome 62

From the jQuery docs

Calling .off() with no arguments removes all handlers attached to the elements. Specific event handlers can be removed on elements by providing combinations of event names, namespaces, selectors, or handler function names.

So in summation the $(window) gives us a reference to the window object that is wrapped in a jQuery object. This wrapper gives us access to jQuery APIs that are available on the object (such as .off). Calling .off() and providing the string beforeunload will remove any event listeners that were previously listening for the beforeunload event.

Note: I did play with the vanilla JS approaches I found after some quick research on Google. However, I was not able to get these approaches to work in the allotted time I had to resolve this issue. If someone has a non jQuery method that is still cross browser compatible please comment or post an additional answer. :)

wickdninja

Posted 2013-12-09T08:52:44.650

Reputation: 470

I was unsuccessful using the accepted answer, and jQuery was already available on the page. – wickdninja – 2017-11-21T15:31:54.957

2This would be a better answer if you would explain how to use it, and, ideally, something about how it works. – Scott – 2017-11-21T19:19:14.690

0

so to get the command from @wickdninja working, first install Chrome Developer Tools. Then you can open that and you will see a tab for 'Console'. Click the Console tab. Then to enable jQuery type these commands:

var jqry = document.createElement('script');
jqry.src = "https://code.jquery.com/jquery-3.3.1.min.js";
document.getElementsByTagName('head')[0].appendChild(jqry);
jQuery.noConflict();

Then type:

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

after that i am able to open/close my gmail without getting the 'Leave?' prompt. https://developers.google.com/web/tools/chrome-devtools/console/javascript

hope this helps.

Lee Hounshell

Posted 2013-12-09T08:52:44.650

Reputation: 101

That solutions don't work. Also I don't understand how to "install Chrome Developer Tools". Chrome Developer Tool is a part of Chrome Browser already. There is no way to install/uninstall it. – Argus – 2020-01-30T07:13:01.457

-4

You can disable Javascript on a site-by-site basis. Go to Settings --> Show advanced settings --> Privacy --> Content settings --> Javascript --> Manage exceptions.

Alexis Huxley

Posted 2013-12-09T08:52:44.650

Reputation: 1

4Yes, but that will disable more than just the message. – BenjiWiebe – 2014-07-17T12:41:49.050

In FIrefox at least, disallowing facebook to run javascript doesn't even accomplish what the OP intends as the page simply keeps reloading the script without executing it. – brokkr – 2015-03-30T15:22:39.890