5

On some pages, if you started typing and then accidentally close your tab or navigate to another page, there would be a confirmation popup:

enter image description here

However, this is site-dependent and many websites do not support this feature.

Is there a Chrome addon that asks for a confirmation for every page when I try to leave a page that has data in <input>s and <textarea>s?

  • (FWIW - you'd normally say 'extension' in Chrome rather than 'addon'. Don't know whether that's technically correct tho) – ᔕᖺᘎᕊ Jun 5 '15 at 21:28
  • @ᔕᖺᘎᕊ, If I say "extension" people might think I only want "extension". But I welcome "plugins" and "userscripts" too. "Addon" includes all that and all auxiliary stuff. – Pacerier Jun 6 '15 at 21:53
  • Makes sense :) Was just saying what is 'commonly' said :) – ᔕᖺᘎᕊ Jun 6 '15 at 21:54
  • It's a critical security bug in Chrome, and it has been reported by many angry users who wish to disable it, yet the chrome devs won't listen. They are morons, it seems. bugzilla.mozilla.org/show_bug.cgi?id=578828#c76 – EveryoneIsStupid Nov 10 '16 at 17:38
  • @EveryoneIsStupid In what way is it a security problem? and why do you link to a page about Firefox when the question is about Chrome? – Judith Nov 10 '16 at 18:48
3

Don't know about an extension but here's a userscript I've made that does just what you want:

// ==UserScript==
// @name         Are you sure you want to leave the page?
// @namespace    http://stackexchange.com/users/4337810/
// @version      1.0
// @description  Adds a confirmation dialog to all pages you browser that have an input or textarea in it
// @author       ᔕᖺᘎᕊ (http://stackexchange.com/users/4337810/)
// @match        *://*/*
// @grant        none
// ==/UserScript==

document.addEventListener('DOMContentLoaded', function() {
    var script = document.createElement('script'),
        head = document.getElementsByTagName('head')[0];   

    script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js";            

    if (typeof jQuery=='undefined') {
        head.appendChild(script);
    }

    window.onbeforeunload = function () {   
        if($('textarea').length || $('input').length){
            if($.trim($('textarea').val()) != '' || $.trim($('input').val()) != ''){
                return "Do you really want to navigate away? Anything you have written will be lost!";       
            }
        };
    }
}, false);

To use it, install Tampermonkey, and then, this script.

Please do note though that this might trigger on a lot of pages you visit - because almost all websites nowadays have a search bar which is an input! But I've added another check to it to only ask if the fields are not empty - so hopefully won't :). You can exclude sites if you want by adding // @exclude <site_url> to the metadata block :)

protected by Community Jan 16 at 7:33

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.