Do You Want To Leave This Site ?” Alert? Appian Community

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

You are watching: Do you want to leave this site

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.

*

*

Using jQuery

$(window).off(“beforeunload”); // tested in IE 11 and Chrome 62From 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. 🙂

Share
Improve this answer
Follow
edited Nov 21 “17 at 19:39
answered Nov 21 “17 at 15:30

*

wickdninjawickdninja
61055 silver badges66 bronze badges
2
Add a comment |
2
$(window).off(“beforeunload.windowReload”);This is worked for me.

See more: Calories In Burger King Iced Coffee Calories In Burger King Vanilla Iced Coffee

Share
Improve this answer
Follow
edited Aug 21 “19 at 16:47

*

Dennis Y. Parygin
10344 bronze badges
answered Aug 9 “17 at 11:38

*

Ashwini K RAshwini K R
3911 bronze badge
3
Add a comment |
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.

Share
Improve this answer
Follow
answered Jun 13 “19 at 5:40
Lee HounshellLee Hounshell
10111 bronze badge
1
Add a comment |
0
Here”s an alternative, manual way to remove beforeunload event listeners:

Right click your web page in Chrome and choose Inspect from the menu, or type Ctrl+Shift+I.Make sure you are in the Elements tab and that the right side panel is visible, if it isn”t make sure the Inspect window is wide enough.On the right side panel pick the “Event Listeners” tab.Locate the beforeunload event listener in the list and expand itUse the “Remove” button for all the event listeners under it.

*

And a vanilla-JS way that doesn”t require jQuery. Thanks to Mike Sraj:

function removeListenersFromElement(element, listenerType){ const listeners = getEventListeners(element); let l = listeners.length; for(let i = l-1; i >=0; i–) { removeEventListener(listenerType, listeners.listener); }}removeListenersFromElement(window, “beforeunload”);
Share
Improve this answer
Follow
edited Jun 30 “20 at 10:31
answered Jun 30 “20 at 10:08
eligelig
14199 bronze badges
Add a comment |
-5
You can disable Javascript on a site-by-site basis. Go to Settings –> Show advanced settings –> Privacy –> Content settings –> Javascript –> Manage exceptions.

Share
Improve this answer
Follow
answered Jul 17 “14 at 12:21
Alexis HuxleyAlexis Huxley
1
2
Add a comment |

Your Answer

Thanks for contributing an answer to Super User!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

See more: Rise Of Iron Level 40 Boost, Where&#39S My Level 40 Boost At

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Submit

Post as a guest

Name
Email Required, but never shown

Post as a guest

Name
Email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

The Overflow Blog
Featured on Meta
Linked
0
Turn off Chrome's “Leave site” warning?
0
How do I disable Google Chrome's pop-ups?
Related
38
How to disable browser cache in Chrome
22
How can I disable javascript popups/alerts in Chrome?
1
Change “Oops! Google Chrome could not connect to this page” screen
17
Disable Javascript for certain page in Chrome
9
Chrome disable white blank page flash before website is loaded
0
How to disable beforeunload events (e.g. “Are you sure you want to leave this page?”) in web browsers?
4
Chrome Disable “Translate This Page?” pop-up, but keep translation feature
0
How do you disable the “sharing this tab” message in Chrome
Hot Network Questions more hot questions

Question feed
Subscribe to RSS
Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Super User
Company
Stack Exchange Network
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.10.18.40487

Super User works best with JavaScript enabled

*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Published

Leave a comment

Your email address will not be published. Required fields are marked *