January 12, 201115 yr Hey guys a little problem with a piece of code I found on the net. Heres a link to the site where the guy is explaining what it does: http://www.tedpavlic.com/post_detect_refresh_with_javascript.php The code works fine in IE and firefox, but not opera. Any of you guys ever experienced this? Anyone know of any fixes? Here's the code: [simply displays 'TEST' when the page is refresh as explained in the link] <script language="JavaScript"> <!-- function checkRefresh() { var today = new Date(); var now = today.getUTCSeconds(); var cookie = document.cookie; var cookieArray = cookie.split('; '); for(var loop=0; loop < cookieArray.length; loop++) { var nameValue = cookieArray[loop].split('='); if( nameValue[0].toString() == 'SHTS' ) { var cookieTime = parseInt( nameValue[1] ); } else if( nameValue[0].toString() == 'SHTSP' ) { var cookieName = nameValue[1]; } } if( cookieName && cookieTime && cookieName == escape(location.href) && Math.abs(now - cookieTime) < 5 ) { alert("TEST"); } } function prepareForRefresh() { if( refresh_prepare > 0 ) { var today = new Date(); var now = today.getUTCSeconds(); document.cookie = 'SHTS=' + now + ';'; document.cookie = 'SHTSP=' + escape(location.href) + ';'; } else { document.cookie = 'SHTS=;'; document.cookie = 'SHTSP=;'; } } function disableRefreshDetection() { refresh_prepare = 0; return true; } var refresh_prepare = 1; --> </script> And my body tag: <body id="home" onLoad="JavaScript:checkRefresh();" onUnload="JavaScript:prepareForRefresh();"> So if any of you guys could recommend a fix or work around it'd be greatly appreciated. Thanks for any help, and of course +1's for your efforts Edited January 12, 201115 yr by pippin
Create an account or sign in to comment