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, 2015 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, 2015 at 21:53
  • Makes sense :) Was just saying what is 'commonly' said :) Jun 6, 2015 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 Nov 10, 2016 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, 2016 at 18:48

1 Answer 1


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') {

    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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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