I wrote a script which redirects user on page refresh. I got it working on newer versions of Firefox, chrome and Internet explorer. However, most of my users still using older version of browsers and this script is not working on those. Which approaching I should do to get it working ?
var redirecting= false;
window.onbeforeunload = function() {
if (redirecting) return;
setTimeout(function() {
window.top.location.href= 'http://www.google.com';
setTimeout(function() {
redirecting=true;
}, 1000);
}, 1);
};