Hi, Im not sure why this code is not working on IE browsers but on chrome its working well. This code is for a Popup, that will ask the users if stay or leave page once they try to refresh or go to other webpage. (you can test www.thesuperheroblueprint.com).. and what ever they choose, the should be redirected on a particular page.

<script type="text/javascript">
// Popup window code
function newPopup(url) {
    popupWindow = window.open(
        url,'popUpWindow','height=500,width=600,left=10,top=10,resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no')
}
</script>
</div>
<!---Exit Pop-->
<script language="javascript">
(function() {
    setTimeout(function() {
    var __redirect_to = 'http://thesuperheroblueprint.com/exit.html';//

    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! PAGE. I HAVE SOMETHING VERY SPECIAL FOR YOU COMPLETELY FREE.';
    }
    }, 500);
})();
</script>
<!--End Exit Pop-->

Hope you can give me a hint or help to fix this. Thank You

I found no errors in the script, nor any culprit in the script for it not to run; even problems with older IE versions.
My guess here is, maybe there is/are extentions in your IE that perturbs its execution; or misconfigurations.

Member Avatar for stbuchok

Honestly, I would remove this altogether. I know you want help with the script, but think about your users first and foremost. If I went to your site and it asked me if "Are you sure you really want to leave", I would click yes and never come back. Ask people how annoying they find this, actually, ask yourself how annoying you find this on other sites.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.