Home > Questions and Answers > General Questions

Exit Pop Up Sciript for IE, Firefox, and Chrome (1)


05-27-2015 05:12 PM #1 smalcolm (AMC Alumnus)
Exit Pop Up Sciript for IE, Firefox, and Chrome

I figured this would be as easy as typing "exit pop up script" into google and copying a couple lines of code, but that doesn't seem to be the case. The code I found doing this is:

Code:
<script language="javascript">
(function() {
    setTimeout(function() {
    var __redirect_to = 'YOUR URL';//

    var _tags = ['button', 'input', 'a'], _els, _i, _i2;
    for(_i in _tags) {
        _els = document.getElementsByTagName(_tags[_i]);
        for(_i2 in _els) {
            if((_tags[_i] == 'input' && _els[_i2].type != 'button' && _els[_i2].type != 'submit' && _els[_i2].type != 'image') || _els[_i2].target == '_blank') continue;
            _els[_i2].onclick = function() {window.onbeforeunload = function(){};}
        }
   }

    window.onbeforeunload = function() {
        setTimeout(function() {
            window.onbeforeunload = function() {};
            setTimeout(function() {
                document.location.href = __redirect_to;
            }, 500);
        },5);
        return 'WAIT BEFORE YOU GO! CLICK THE *CANCEL* BUTTON RIGHT NOW! I HAVE SOMETHING VERY SPECIAL FOR YOU.';
    }
    }, 500);
})();
</script>
This code works fine for IE, but in Firefox and Chrome, it just returns the default exit pop up rather than the message I wrote. Can anybody point me in the direction of a working exit pop up that works for IE, Firefox, and Chrome?

Thanks,
Adam


Home > Questions and Answers > General Questions