Hi,
How can I close the current browser window after user click the button?
I know Javascript "window.close" can do so, but is it possible to do it in ASP .NET?
Regards,
Calvin
Printable View
Hi,
How can I close the current browser window after user click the button?
I know Javascript "window.close" can do so, but is it possible to do it in ASP .NET?
Regards,
Calvin
You'll have to use Javascript as server side technology can't close a client-side browser.
Hi YellowCat,
You can response.write some Javascript to the client browser...
i.e
Private Sub Closewindow(Sender as Object, E as EventArgs)
Dim jScriptString as String
jScriptString = "<SCR" + "IPT>"
jScriptString += "window.close();"
jScriptstring += "</SCR" + "IPT>"
Response.Write(jScriptString)
End Sub
There's loads of different ways you can action this but at the end of the day you've still got to use script.
Just remember, the browser will dialog to the user stating the web page is trying to close the browser, unless it was a window initially opened by javascript.
now I use following code to close the browser window:
Dim strScript As String
strScript = "<script language='javascript'>window.close()/script>"
Page.RegisterStartupScript("Script", strScript)
Is it the best way to do that?
Regards,
Calvin
Well, depends on your view....
I would say just throw an OnClick attribute in the actual aspx html to close the window...
Or you could do it the way you suggested.
My way means the server doesn't have to process the button click and register script at page render.
Your way is a tad more secure and seperates user interface from code logic... in my way, a web-designer or malicious person can edit the html client-side. but then that all depends if javascript is even enabled.
Really its up to you. Like I said, the user can always say 'No' to the IE dialog requesting the user to allow the web page to close the browser window (unless it was initally opened by javascript, in which case it simply closes).
so, how can I close the browser window in 'OnClick' events? Could you mind to give me some hints?
Code:<input type="button" value="close" onClick="window.Close();">