How to redirect after ALERT.

A

Alexis Faren

Good Easter to all.

I am using this code to raise an Alert and it works fine. What I'd like to do is to redirect the user to the previous page based on this script:

.... OTHER CODE HERE

If NOT rsAccounts.EOF Then
rsAccounts.close

strMSG = "HOLD ON " & UCase(session("LoggedUser")) & "!\n\n"
strMSG = strMsg & "You have already made your selections!\n\n"
strMSG = strMsg & "Email the adminsitrator to have them deleted!"

Response.Write("<" & "script>alert('" & strMSG & "');" & "<" & "/script>")

End if
%>

I've tried using location.href and response.redirect to no avail.

I need to do this right after Response.Write.

Could someone point me in the right direction please?

Thanks to all
 
A

Alexis Faren

Sorry folks, my bad. I said the PREVIOUS Page, but it could be any page.

Sorry about that.

Alexis.
Good Easter to all.

I am using this code to raise an Alert and it works fine. What I'd like to do is to redirect the user to the previous page based on this script:

... OTHER CODE HERE

If NOT rsAccounts.EOF Then
rsAccounts.close

strMSG = "HOLD ON " & UCase(session("LoggedUser")) & "!\n\n"
strMSG = strMsg & "You have already made your selections!\n\n"
strMSG = strMsg & "Email the adminsitrator to have them deleted!"

Response.Write("<" & "script>alert('" & strMSG & "');" & "<" & "/script>")

End if
%>

I've tried using location.href and response.redirect to no avail.

I need to do this right after Response.Write.

Could someone point me in the right direction please?

Thanks to all
 
B

Bob Barrows

Server-side code has no concept of document, or window or location, etc.
HTTP is a stateless protocol so the previous page typically is not known.
The only objects available to server-side code are Request, Response,
Server, Session and Application, along with COM objects that are used via
CreateObject.

You really need to make an effort to keep this in mind. It's one of the
biggest hurdles for novice web developers.

However, if the browser bothers to populate it, the HTTP_REFERER
servervariable will contain the url of the page that submitted the request:

submitter = Request.ServerVariables("HTTP_REFERER")

I think all modern browsers will populate this variable (barring security
settings that the user may have set) so this should be OK, However, an
alternative that might be a little more robust is to add the client-side
call to the history object to your response.write that raises the alert:

Response.Write "<" & "script>alert('" & strMSG & "');" & _
"window.history.back();" & "<" & "/script>"
Response.End

By the way, the above can be simplified by switching out of the server-side
code block:

<%
... OTHER CODE HERE

If NOT rsAccounts.EOF Then
rsAccounts.close

strMSG = "HOLD ON " & UCase(session("LoggedUser")) & "!\n\n"
strMSG = strMsg & "You have already made your selections!\n\n"
strMSG = strMsg & "Email the adminsitrator to have them deleted!"
%>
<script type="text/javascript">
alert('<%= strMSG %>');
window.history.back();
</script>
<%
Response.End
End If
..%>
 
A

Alexis Faren

Actually I reviewed my ALERT code and thought "What the Heck...".

So I just did this:

Response.Write("<" & "script>location.href=('" & redir & "');")
Response.Write("<" & "/script>")

Works like a hot darn.

Also, I did try switching from server block to client bock, but it wouldn't
work consistently in FF (IE seemed OK). So I needed more complete solution.

I should have posted that little detail as well - my bad.

Thanks Bob...

btw: I've gotten a lot from this site, everyone here does an excellent job
in helping novices and others.
KOODOS!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top