Results 1 to 11 of 11

Thread: Close browser window without prompt

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Close browser window without prompt

    Hi all,

    I'm using the following javascript to close a browser window:
    Code:
    Response.Write("<script language='javascript'> { window.close();}</script>")
    It works good but I get the confirmation prompt. Is there a way I can modify the above syntax so it closes the browser window without the confirmation prompt? I'm using VS 2008 and ASP.NET 2.0

    Thanks,

    Strick

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

    Re: Close browser window without prompt

    If you did a forum search you'd come across this solution posted by Mendhak a little under one month ago. It should work but it's evil. EVIL!
    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Re: Close browser window without prompt

    Hello,

    Thank you for you response. I still get the prompt even when using the code from the post you provided. Here is how I'm using it:

    Code:
            Response.Write("<script language='javascript'> { window.opener='blah';window.close();}</script>")
    Thanks,

    Strick

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

    Re: Close browser window without prompt

    Not sure then as it's something I've never fiddled with. I'm sure Mendhak will come across this post and help with his own code though, heh.

    I always thought the opener being the same as the parent would allow you to close it but his code goes the other way so I'm not sure.
    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

  5. #5
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: Close browser window without prompt

    Hm.. it works for me. What browser you used? I used in this context:

    HyperLink1.NavigateUrl = "javascript:window.opener='blah';window.close();";

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Re: Close browser window without prompt

    Hi, Using IE7. Haven't tried it on IE6 yet? Also I'm using the response.write to execute the javascript in my code (the code I'm using is in my previous post) so I don't have to assign it to a hyperlink. My code works, but it's still prompting to close the window. But if I have to use a hyperlink to do it I guess thats the way I'll have to go. I'll try that this evening when I get home and let you know.

    Thanks for your help.

    Strick

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

    Re: Close browser window without prompt

    Remove the curly braces. They mean nothing if it's not in a function.

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

    Re: Close browser window without prompt

    PS: Yes, quite evil. What have I unleashed!

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

    Re: Close browser window without prompt

    Quote Originally Posted by mendhak
    Remove the curly braces. They mean nothing if it's not in a function.
    The curly braces just define a block and not necessarily a function .
    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

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

    Re: Close browser window without prompt

    Keep your code clean.

  11. #11
    New Member
    Join Date
    Apr 2009
    Posts
    1

    Re: Close browser window without prompt

    Quote Originally Posted by stricknyn View Post
    Hi, Using IE7. Haven't tried it on IE6 yet? Also I'm using the response.write to execute the javascript in my code (the code I'm using is in my previous post) so I don't have to assign it to a hyperlink. My code works, but it's still prompting to close the window. But if I have to use a hyperlink to do it I guess thats the way I'll have to go. I'll try that this evening when I get home and let you know.

    Thanks for your help.

    Strick
    For IE7 you can use this:

    window.open('', '_self', '');
    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