Hello, I want to add a link to my page "close the browser", when the user clicks on that link, it will close the browser. Is there an easy way in c#?
Printable View
Hello, I want to add a link to my page "close the browser", when the user clicks on that link, it will close the browser. Is there an easy way in c#?
forgot to mention, I want to use the hyperlink control to close the browser
Since this code has to run on the client side (a server cannot tell a browser window to close) the code has to be written in JavaScript.
Not I'm not sure if there is a way to do this in C# that ASP.Net translates into JavaScript but you would essentially put this in your link's address:
Please note that IE will tell the user that the web page is requesting that the browser window be closed. Some browsers ignore this request completely and only in very few situations will it close without notifying the user (i.e. the user clicks a button and its immediate effect is closing the window).Code:javascript:window.close();
In my opinion doing this is typically bad form and/or a user experience no-no but there are some cases where I think it's ok (such as a close button on a pop-up).
To do it without a warning,
I agree that it's bad for user experience especially if it's on the main page of the site. It's a way of saying "Dear user, you are obviously too stupid to use the X button in your toolbar, so here's a close button for you; now that we're done patronizing, do visit our site more often so that we can treat you like this further."Code:javascript:window.opener='blah';window.close();
how can I put that into the hyperlink control?
Oh nevermind.
Thank you.
HyperLink1.NavigateUrl = "javascript:window.opener='blah';window.close();";