How can I call javascript just before redirecting a response

I try to run a java script just before reconfiguring the page, but it does not start. When I comment on Response.Redirect, everything works fine, but it is contrary to specific 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")  
+3
source share
5 answers

Your problem is that Response.Redirect redirects the response (...) before anything is sent back to the client. So the client receives a response from Google, and not from your server.

javascript Google, javascript .

   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
+12

. :

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
+3

- javascript , javascript, ASP.NET.

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
+2

:

string sScript = "<script language='javascript'>alert(\"" + Alertstr + "\");  alert('Record has been Updated Successfully'); </script>";
ClientScript.RegisterStartupScript(typeof(Page), "alert", sScript);
response.redirect("LandingPage.aspx");

:

string sScript = "<script language='javascript'>alert(\"" + Alertstr + "\");  alert('Record has been Updated Successfully'); window.location.href = 'LandingPage.aspx'; </script>";
ClientScript.RegisterStartupScript(typeof(Page), "alert", sScript);
+1

Response.Redirect, 3XX , URL- . / , ( , - ). , , META refresh header, javascript script.

0

Source: https://habr.com/ru/post/1704667/


All Articles