javascript - How I can track if users closes tab and show him research window? -


so, example. want track if user leaves landing page without doing (not leaves, closes tab), , stop closing, show him form several questions research. (if clicks close again or submits form tab should closed). possible? may hints how can done? know of browsers have protection spaming user alerts , on.

you need this

    function formisdirty(form) {     (var = 0; < form.elements.length; i++) {         var element = form.elements[i];         var type = element.type;         if (type == "checkbox" || type == "radio") {             if (element.checked != element.defaultchecked) {                 return true;             }         }         else if (type == "hidden" || type == "password" ||                  type == "text" || type == "textarea") {             if (element.value != element.defaultvalue) {                 return true;             }         }         else if (type == "select-one" || type == "select-multiple") {             (var j = 0; j < element.options.length; j++) {                 if (element.options[j].selected !=                     element.options[j].defaultselected) {                     return true;                 }             }         }     }     return false; }           window.onbeforeunload = function (e) {             e = e || window.event;             if (!formisdirty(document.getelementbyid(formid))) {                 // ie , firefox                 if (e) {                     e.returnvalue = message;                 }                 // safari                 return message;             }         }; 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -