VB icon

Get page from server when user presses the back or forward button

Email
Submitted on: 1/5/2015 5:19:00 PM
By: Vikas Kumar (from psc cd)  
Level: Advanced
User Rating: By 8 Users
Compatibility: ASP (Active Server Pages), HTML, VbScript (browser/client side)
Views: 621
 
     I searched high and low for a code which will allow me to get a fresh copy of my page even if the user presses the back or the ofrward button. Finally i gave up and wrote my own. Expires and no-cache do not cache the page but it will still go into the history and can be retreived by the back button without going to the server It needs IE5 or above to run
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Get page from server when user presses the back or forward button
' Description:I searched high and low for a code which will allow me to get a fresh copy of my page even if the user presses the back or the ofrward button. Finally i gave up and wrote my own.
Expires and no-cache do not cache the page but it will still go into the history and can be retreived by the back button without going to the server
It needs IE5 or above to run
' By: Vikas Kumar (from psc cd)
'
' Assumes:Required IE5 or more
'**************************************

cut the code below a save it as a asp.
when you run this code after pressing the back/forard button you will see it will automatically refresh
<%@ Language=VBScript %>
<%Response.Expires=0%>
<HTML>
<HEAD>
<META NAME="save" CONTENT="history">
<STYLE>
 .saveHistory {behavior:url(#default#saveHistory);}
</STYLE>
<SCRIPT>
var RandomValue;
 function fnSaveInput(){
oPersistInput.setAttribute("sPersistValue",PersistedValue);
 }
 function fnLoadInput(){
oPersistInput.value=oPersistInput.getAttribute("sPersistValue");
RandomValue=oPersistInput.getAttribute("sPersistValue");
 }
 function f1()
 {
 if (RandomValue==PersistedValue)
	{window.location.reload(true)
	}
 }
</SCRIPT>
<%
Response.Write("<SCRIPT>")
Response.Write("var PersistedValue = '" & Now() & "';")
Response.Write("</SCRIPT>")
%>
</HEAD>
<BODY onload='f1()'>
<INPUT class=saveHistory onsave="fnSaveInput()" onload="fnLoadInput()" type=text id=oPersistInput>
</BODY>
<%
Response.Write(Now())
%>
</HTML>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.