• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

how can I referesh my page as soon as it is started loading my code?

I want to refersh my page  only one time, as soon as the page load,
how can I do that?
I have a page inculude a flash swf file, although I use below code to clean the cache, sometimes they see still the old swf file.
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />

what should I do?
thank you in advance.
0
Braveheartli
Asked:
Braveheartli
3 Solutions
 
Pratima PharandeCommented:
Try like this
add this script on page
<script language="JavaScript"> <!--
function checkRefresh()
{
      if( document.refreshForm.visited.value == "" )
      {
            // This is a fresh page load
            document.refreshForm.visited.value = "1";
        history.go(0);
            // You may want to add code here special for
            // fresh page loads
      }
      else
      {
            // This is a page refresh
                 // Insert code here representing what to do on
            // a refresh
      }
}
</script>

Sample page below
<html>
<head>
 
<script language="JavaScript"> <!--
function checkRefresh()
{
	if( document.refreshForm.visited.value == "" )
	{
		// This is a fresh page load
		document.refreshForm.visited.value = "1";
        history.go(0);
		// You may want to add code here special for
		// fresh page loads
	}
	else
	{
		// This is a page refresh
     		// Insert code here representing what to do on
		// a refresh
	}
}
</script>
 
</head>
 
<body onLoad="JavaScript:checkRefresh();">
 
<form name="refreshForm">
<input type="hidden" name="visited" value="" />Test
</form>
 
</body>
</html>

Open in new window

0
 
striker46Commented:
Try this possible solution,  does not involve refreshing. It attempts to avoid especially IE caching urls.
var url contains the URL where the SWF file is fetched from.

Every time a visitor loads the page, the SWF will be fetched but in the end of the source URL the timestamp is included (as a variable), so making the URL be different every time.

Code snippet below



// Customise SWF URL
 
var swfurl = "yoururlhere";
 
// Generate timestamp to avoid cache
 
fetch_timestamp = function(){  
return parseInt(new Date().getTime().toString().substring(0, 10));  
}  
 
// Put URL and timestamp together
 
var timestamp = fetch_timestamp();  
var url = swfurl+"?t="+timestamp;  

Open in new window

0
 
BraveheartliMarketingAuthor Commented:
Thank you for your wonderful reply,
Can I do that without a form and with minumum code?
0
 
Pratima PharandeCommented:
without form
<html>
<head>
 
<script language="JavaScript"> <!--
function checkRefresh()
{
	if( document.getElementById("visited").value == "" )
	{
		// This is a fresh page load
		document.getElementById("visited").value = "1";
        history.go(0);
		// You may want to add code here special for
		// fresh page loads
	}
 
}
</script>
 
</head>
<body onLoad="JavaScript:checkRefresh();">
<input type="hidden" id ="visited" name="visited" value="" />Test
</body>
</html>

Open in new window

0
 
obareeyCommented:
you can do that also with cookies. here is a few document about it.

http://www.quirksmode.org/js/cookies.html
http://www.w3schools.com/JS/js_cookies.asp
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now