Saturday, April 13, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  175] [ 4]  / answers: 1 / hits: 17973  / 15 Years ago, thu, march 12, 2009, 12:00:00

I'm trying to run some java script just before a page redirect but it fails to run.
When I comment out the Response.Redirect all works fine but this goes against the particular requirements. Any ideas on how to implement this functionality?



        Dim strscript As String = <script>alert('hello');</script>

If Not ClientScript.IsClientScriptBlockRegistered(clientscript) Then
ClientScript.RegisterStartupScript(Me.GetType(), clientscript, strscript)
End If

Response.Redirect(http://www.google.com)

More From » asp.net

 Answers
24

Your problem is that the Response.Redirect redirects the response (...) before anything is sent back to the client. So what the client gets is a response from Google rather than from your server.



In order to write some javascript on the page and have it execute before sending the client to Google, you'll need to do your redirect in javascript after the alert.



   Dim strscript As String = <script>alert('hello');window.location.href='http://www.google.com'</script>

If Not ClientScript.IsClientScriptBlockRegistered(clientscript) Then
ClientScript.RegisterStartupScript(Me.GetType(), clientscript, strscript)
End If

[#99858] Friday, March 6, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andreguym

Total Points: 125
Total Questions: 112
Total Answers: 103

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;