Results 1 to 8 of 8

Thread: Closing window without confirmation prompt

  1. #1
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default Closing window without confirmation prompt

    Hi

    I need a method to close the main browser window using
    Code:
    window.close()
    without getting a confirmation prompt.

    Is this possible or is there any other way to achieve the same result?

    Any help will be highly appreciated.

    Regards

  2. #2
    Join Date
    Jan 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Try this...

    Please have a look to the attachment(open.html).Its just a work around as I think its not possible to close the browAttachment 760eser window without an alert msg.

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    The files you attached in your posting doesn't working as I want. Let me clear my points.

    1. I have only one window which is not generated using script. (There is no scope for a popup window in my case).

    2. I need to close my only window (main window) using JavaScript code in such a way that it doesn't show the browser closing confirmation box.

  4. #4
    Join Date
    Jan 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Fine ...I got your point.
    Please try this attachment. I tested it in i.e.6.0. Its working fine Attachment 761.
    code:
    <script language="JavaScript">
    function fCloseOpener(){
    window.opener = self
    window.close()
    }
    </script>
    Last edited by beeps; 01-31-2007 at 09:00 AM. Reason: attachment

  5. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by beeps View Post
    Fine ...I got your point.
    Please try this attachment. I tested it in i.e.6.0. Its working fine Attachment 761.
    code:
    <script language="JavaScript">
    function fCloseOpener(){
    window.opener = self
    window.close()
    }
    </script>
    In IE 7 the above code doesn't work correctly.

    I've tested it with IE 6 and the window seems to be stucked it did not close for me.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    John came up with a code that does this. It convinces JS that the window WAS opened by it then allows it to close the window. Search around for it... not sure where it is at the moment.

    Edit: here we go...

    Code:
    <script type="text/javascript">
    if(window.name!='prime'){
    window.name='prime';
    window.open(window.location.href, 'prime')
    }
    </script>
    He said, in short, that once this is on the page, it allows window.close() etc. to work properly.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I found that, for some reason, IE versions 6 and below didn't like that but, they always had responded well to another hack that other browsers ignored so, in the end I went with this:

    Code:
    <script type="text/javascript">
    if(window.name!='prime'){
    window.name='prime';
    window.open(window.location.href, 'prime')
    }
    </script>
    <!--[if lte IE 6]>
    <script type="text/javascript">
    window.opener=self;
    </script>
    <![endif]-->
    What it does is to reopen the window in the same window using javascript based upon whether or not it has the name 'prime'. Then (except in IE 6 and below) it can be closed using javascript. In IE 6 and less it also tells the browser, "Hey - I am the opener so, you can close me with javascript."

    This has the side effect of assigning the window the name of 'prime' (or changing its name to that if it had one). This could cause problems if you have any other code that relies upon the window's name being something else or null. But, this should be able to be worked around if it is at issue in your setup.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks :)

    @ djr33

    Thanks for explaining.

    Thank you everyone.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •