redirect to prev page

I am using ASP Classic.

I am currently using the script below on a page that has a stored procedure. It redirects to a specific page.

<script language="javascript">
window.location.href="Index.asp";
</script>

I need to tweak it so that it redirects to the PREVIOUS page.

Right now I have two pages that go to this one and because the redirect is fixed I need to pages to go back to the correct previous page.
Hope that makes sense.
LVL 1
AleksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
a quick fix is using history.back()

<script language="javascript">
history.back();
</script>

Open in new window


see if this serve the purpose, or else you could probably do this by referring to server side variable HTTP_REFERRER and redirect accordingly.

<script language="javascript">
window.location.href="<%= Request.ServerVariables("HTTP_REFERER")%>";
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
Second option worked perfectly, thanks !
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
If you are using a server side language, why would you use javascript?  If your are hitting your SP via a javascript ajax call, then using js to go back makes sense.  If your user is directed to a page (even if they don't "see" it) by your asp code, then you would probably be better off using response.redirect.

<%
set Conn = Server.createObject("ADODB.Connection")
Conn.open(my_connection_string)
set Cmd = Server.createObject("ADODB.Command")
set Cmd.activeConnection = Conn
Cmd.commandType = adCmdStoredProc
':
' stored proc code
':
set Cmd.activeConnection = nothing
set Cmd = nothing

Conn.close()
set Conn = nothing

' now redirect
response.redirect("my_new_page.asp")
%>

Open in new window

0
AleksAuthor Commented:
Sorry forgot to click accept.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.