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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

History back

Status
Not open for further replies.

lb1

Technical User
Apr 19, 2002
109
US
How can I go back one or two window back. I now how to use the javacript function , but how this can be done in ASP.

The code, I believe is : window.history.go -1 - goback

but when I am using it I get the following error message:

Microsoft VBScript runtime error '800a01a8'

Object required: 'window'

Any help will be appreciated.
Thanks
Louis

 
never tried but
response.redirect "history.go(-1)"

may work I help at your own risk, if I brake it sorry! But if I fixed it, let me know.[thumbsup2]
admin@onpntwebdesigns.com
 
this works
<%
response.write(&quot;<A href='#' onclick='&quot;)

response.write(&quot;history.go(-1)'>&quot;)

response.write(&quot;hello!&quot;)
%> I help at your own risk, if I brake it sorry! But if I fixed it, let me know.[thumbsup2]
admin@onpntwebdesigns.com
 
The server is not keeping track of where the visitor has been, so therefore any server-side code to send a client back a page or two would either have to be coded to keep track using a cookie or session variable (intersesting idea, you could just save the url they request each time and use querystrigs throughout the site) or would have to execute a client-side script.
A quick and not so pretty way would be to give them a page that had no content beyond:
<html>
<body onload=&quot;history.go(-1)&quot;>
</body>
</html>

this would work as suggested above. If you want a purely server side approach I would suggest finding a way to save each url they request (in order) along with form variables they pass. Again, I would probably want to go with querystrings to make this task easier or just make the page capable of reading form info or querystrings and save your form info as a url with querystrings. That way you can return to the same exact state, unfortunatly this is not a true back and will still re-execute anything on that page, requiring you to make sure you are not re-submitting data to a database from three pages ago when you decide the client should go back.
-Tarwn
 
I think think what is needed here is a little more simple then that. Although all is very true if what is needed is jsut a redirection back on a condition or after a section of code is run then something as simple as this will work.

this is a example of how you would do this on a condition
back.htm
<html>
<body>
<form name=&quot;form1&quot; action=&quot;back.asp&quot; method=&quot;get&quot;>
<input type=&quot;text&quot; name=&quot;txt&quot;>
<input type=&quot;submit&quot; value=&quot;go back&quot;>
</form>
</body>
</html>
back.asp
<%
dim var1,mymsg
var1 = Request.QueryString(&quot;txt&quot;)
if var1 < &quot;2&quot; then
response.write(&quot;<script>&quot;)
response.write(&quot;history.go(-2)&quot;)
Response.Write(&quot;</script>&quot;)
end if
%>

if you want to go back or forward all you need to do is this where you would like to do this. estentialy you are running client side coding but you are doing it server side
response.write(&quot;<script>&quot;)
response.write(&quot;history.go(-2)&quot;)
Response.Write(&quot;</script>&quot;) I help at your own risk, if I brake it sorry! But if I fixed it, let me know.[thumbsup2]
admin@onpntwebdesigns.com
 
This works fine..

<%

Response.Write &quot;<a href=&quot; & Chr(34) & Request.ServerVariables(&quot;HTTP_REFERER&quot;) & Chr(34) & &quot;</a>Go Back&quot;

%>


Jason
 
HTTP_REFERER doesn't work for me... I don't know why. Other server variables do. -Phil
fillup07@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top