Results 1 to 4 of 4

Thread: Closing windows without an alert when running under Vista

  1. #1
    Join Date
    Jan 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Closing windows without an alert when running under Vista

    Hi,

    I have been looking for a quick solution to this and haven't managed to find one yet and I hope someone here can help.

    The code I am using to open a new window is ordinary HTML Ie.

    <a href="austin.html" target="_blank">Robert Austin</a>

    In the new window I use a button to allow the reader to colse it Ie.

    <input type="button" value="Close this window" onClick="window.close();">

    When running under Windows XP this didn't cause a problem but now with VISTA I get an alert message asking if I really want to close the window.

    I have read some info that suggests this is a new 'security' feature in Vista and that there is no way round it. If anyone has found a better way of doing this could you please let me know.

    Thanks

    Marc.

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Code:
    <input type="button" value="Close this window" onClick="window.opener=self;window.close();">
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    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

    That's fooling the browser, or trying to. It will fail in FF and others. The only way to be relatively sure that you can close a window with javascript is to have opened it with javascript:

    Code:
    <a href="austin.html" target="_blank" 
    onclick="window.open(this.href,this.target);return false;">Robert Austin</a>
    Then on austin.htm:

    Code:
    <script type="text/javascript">
    document.write('<input type="button" value="Close this window" onclick="window.opener=self;window.close();">');
    </script>
    Using document.write makes it so that only browsers that can use the button will see the button. It could be refined a little more by testing to see if the page was actually open by javascript, but that's a little complicated to do cross browser, and even if it wasn't opened by javascript, many browsers will still comply. At the least, you will get a confirmation and option to close. But, if the page was gotten to from a link like in the first code block, virtually all browsers will accept the close.
    - John
    ________________________

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

  4. #4
    Join Date
    Jan 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks!

    Thanks for the solution that has solved quite a big problem ) now all I have to do is a bunch of editing

    Regards


    Marc

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
  •