Important alert: (current site time 7/15/2013 11:49:33 PM EDT)
 

VB icon

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

Email
Submitted on: 7/23/2001 4:21:42 PM
By: Vikas Kumar 
Level: Advanced
User Rating: By 8 Users
Compatibility: ASP (Active Server Pages), HTML, VbScript (browser/client side)
Views: 19899
 
     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!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' 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
'
' Assumes:Required IE5 or more
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6799&lngWId=4'for details.'**************************************

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

7/27/2001 5:11:43 AMAquarius

GREATTTTTT CODE!!!! i badly needed this on my project i'm currently working on!!!
keep it up!!!
(If this comment was disrespectful, please report it.)

 
7/28/2001 1:12:10 PMPranab

Great code
Really useful
(If this comment was disrespectful, please report it.)

 
7/30/2001 1:45:40 PMCarlos

Works very well, thanks!
(If this comment was disrespectful, please report it.)

 
9/13/2001 2:43:28 PMvbuser1976

I had been spending days trying to accomplish this. Thanks, it is great. But I noticed one little problem: It needs a little adjustment when you use it on a frameset page.
(If this comment was disrespectful, please report it.)

 
1/3/2002 11:24:51 AMIan Livesey

Does not work on my IE6, back and forward still work, please advise!
(If this comment was disrespectful, please report it.)

 
1/3/2002 2:18:21 PMaurora

i need this code for my frameset. i'm not a programmer. how will i do it.
(If this comment was disrespectful, please report it.)

 
1/4/2002 11:15:04 AMIan Livesey

Retried cutting and pasting code from <%@ Language=VBScript %> to
%>

Called it backforward.asp
still does not work, anybody any ideas. I'm running IE6 on XP Pro.
Thanks
(If this comment was disrespectful, please report it.)

 
4/30/2003 6:28:20 AM

Very useful code.

But, I could not use it.
Can you send me with an example.

Thanks.

(If this comment was disrespectful, please report it.)

 
8/17/2004 12:08:07 PMBrett N. Meroney

It seems that the problem is getting the onsave event to fire in IE6 w/ the 'savehistory' behavior...
Does anyone have an update for this code that works effectively w/ IE6?

(If this comment was disrespectful, please report it.)

 

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.