Response.Write() with javascript doesn't work properly
I'm having a problem with this code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
clave = Request.QueryString("cve")
If clave = Nothing Then
Response.Write("<script language='javascript'>alert('Querystring is empty');window.close();</script>")
Return
End If
Dim valid As Boolean
valid = Regex.Match(clave, "\b\d{3}\-\d{3}\-\d{3}\b").Success
If valid = False Then
Response.Write("<script language='javascript'>alert('Wrong format');window.close();</script>")
Return
End If
'More Code
End Sub
The thing is that, the first if statement works fine and the 'javascript' shows an alert and close the window, but in the second if statement the javascript shows the message but doesn't close the window.
Do you guys know how to fix 开发者_C百科this?
The code seems fine.
Try to use Client.RegisterScriptBlock instead.
window.close();
is correct, but for security reasons, most browsers won't let you close windows you didn't open.
精彩评论