|
-
Aug 22nd, 2004, 09:21 PM
#1
Thread Starter
Junior Member
close current browser window
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
-
Aug 23rd, 2004, 06:02 AM
#2
You'll have to use Javascript as server side technology can't close a client-side browser.
-
Aug 23rd, 2004, 06:08 AM
#3
Hyperactive Member
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
-
Aug 23rd, 2004, 07:30 AM
#4
There's loads of different ways you can action this but at the end of the day you've still got to use script.
-
Aug 23rd, 2004, 09:59 AM
#5
I wonder how many charact
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.
-
Aug 23rd, 2004, 11:07 PM
#6
Thread Starter
Junior Member
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
-
Aug 24th, 2004, 09:12 AM
#7
I wonder how many charact
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).
-
Aug 24th, 2004, 09:08 PM
#8
Thread Starter
Junior Member
so, how can I close the browser window in 'OnClick' events? Could you mind to give me some hints?
-
Aug 25th, 2004, 07:02 AM
#9
I wonder how many charact
Code:
<input type="button" value="close" onClick="window.Close();">
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|