Can someone fix this script? Will pay

9 replies
Does anyone know why the following script works perfectly in Chrome and IE, but in FF won't display my custom message? I'll pay anyone who can modify it to work in all 3. Thanks in advance!


<script language="javascript">
(function() {
setTimeout(function() {
var __redirect_to = 'http://mysiteiwanttoredirectto.com/';//

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! Hit the "stay on this page" button to get BIGGER DISCOUNT!';
}
}, 500);
})();
</script>
#fix #pay #script
  • Profile picture of the author kdavies
    I can take a look at it if you want. In the meantime you can use FF's javascript debugger and check for any javascript errors.
    {{ DiscussionBoard.errors[10168431].message }}
  • Profile picture of the author DLycanthus
    I've decided to make my first post here fixing this!

    As usual, with most programming, it's the small stuff that'll get ya. You simply didn't have a few of your functions 'closed' properly, i.e., the semi-colon. And, where you have your = sign's, they should all be one more, like === or !==. Different strokes for different languages. The code below should work fine for you.


    (function() {
    setTimeout(function() {
    var __redirect_to = 'http://www.ENTER_YOUR_SITE_HERE.com';

    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! Hit the "stay on this page" button to get BIGGER DISCOUNT!';
    };
    }, 500);
    })();
    </script>
    Hope that helps!

    Edit: Fixed the print-out back to what you had it as to begin with
    {{ DiscussionBoard.errors[10171077].message }}
    • Profile picture of the author mikey21
      Originally Posted by DLycanthus View Post

      I've decided to make my first post here fixing this!

      As usual, with most programming, it's the small stuff that'll get ya. You simply didn't have a few of your functions 'closed' properly, i.e., the semi-colon. And, where you have your = sign's, they should all be one more, like === or !==. Different strokes for different languages. The code below should work fine for you.

      Hope that helps!

      Edit: Fixed the print-out back to what you had it as to begin with
      Thank you so much for trying!

      However, the following message is still being displayed in FireFox (instead of the print out):

      "This page is asking you to confirm that you want to leave - data you have entered may not be saved."
      {{ DiscussionBoard.errors[10208095].message }}
  • Profile picture of the author Babumonn
    Hi,

    Do you still need help with this?
    {{ DiscussionBoard.errors[10270815].message }}
  • Profile picture of the author engineerz1
    any developer can join me on facebook page for programming help.
    https://www.facebook.com/The-Master-...1783/timeline/
    Signature

    Founder of The Master World

    {{ DiscussionBoard.errors[10273207].message }}

Trending Topics