Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

link -command doesn't work 1

Status
Not open for further replies.

Nogi

Technical User
Dec 10, 2004
132
BE
I have a link on my page that should go to the previous page in history and refresh that page.

This is how i try to make it work

Code:
<a href="<%=referer%>"onclick="location.replace(this.href,true);return false;">BACK</a>

This doesn't work.

Does anyone have an idea why?
 
You are trying to do 2 things at the same time, refresh the current page (which is the page this link is on) with the onclick event and hyperlink (href) to the previous page. So, it will probably fire the onclick event and try to refresh the current page and then move to the new page (i.e. move back) - rather than open the new page and refresh it.

Code:
<a href="javascript:history.back();" title="Go Back">BACK</a>
or
<a href="<%=Request.ServerVariables("HTTP_REFERER")%>" title="Go Back">BACK</a>

The first above will use the browser history to move back to the previous page - this will be like hitting the back button.
The second will use the referer server variable (if it is available, which it isn't always) which will be like visiting the page anew.

However, the browser can still choose to use a cached copy of the page if it is set to do so. To stop this set the cache-control and response.expires etc

Code:
<% 
Response.CacheControl = "no-cache" 
Response.AddHeader "pragma", "no-cache"
Response.Expires = -1
%>

A smile is worth a thousand kind words. So smile, it's easy! :)
 
hey thanks for the post damber. that explains alot really.

 

No problem, glad to help.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top