Results 1 to 6 of 6

Thread: [RESOLVED] closing browser

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Resolved [RESOLVED] closing browser

    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#?

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: closing browser

    forgot to mention, I want to use the hyperlink control to close the browser

  3. #3
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: closing 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:
    Code:
    javascript:window.close();
    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).

    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).
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: closing browser

    To do it without a warning,

    Code:
    javascript:window.opener='blah';window.close();
    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."

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: closing browser

    how can I put that into the hyperlink control?

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: closing browser

    Oh nevermind.

    Thank you.

    HyperLink1.NavigateUrl = "javascript:window.opener='blah';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
  •  



Click Here to Expand Forum to Full Width