Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Refresh detect issue

Featured Replies

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 by pippin

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.