How To Close Window in safari for Mac Os

Discussion in 'Web Design and Development' started by mohan.reddy, Jul 19, 2010.

  1. mohan.reddy macrumors newbie

    Joined:
    Jul 19, 2010
    #1
    Hi............
    The problem is using Safari in Mac Oprating System.I am unable to Close Window using java script window.close() or self.close().I'm using the following code line, which is working fine with all browser of Window OS.

    Code:
    <script type="text/javascript">
    <!--
    self.focus();
    setTimeout("self.close();",10);
    //-->
    </script> 
    and

    HTML:
    <a href="javascript:window.close();">Close this window</a></span>
    Any help most appreciated.

    Mohan Reddy
     
  2. eponym macrumors 6502

    Joined:
    Jul 2, 2010
    #2
    What exactly isn't working?

    And why do you have both a timeout AND a manual close using a link?

    Are you sure it's not working? Both of those work on their own—I double checked. Is there other javascript in this page? You might have an error elsewhere that's killing the script. Use the Web Inspector to see (under the Develop menu, which you'd have to turn on in Safari preferences).

    You might also not be noticing the page loads and closes nearly instantly. JS is very fast in webkit browsers (Safari, Chrome etc). And your duration for the timeout call is 10 milliseconds (i.e. if you want 10 seconds, you need to set it to 10000). So what's happening is before the window is even visible, the timeout of 10 milliseconds passes and it closes the window.


    (Also, just an FYI: you don't need to wrap your script in an HTML comment. That hasn't been necessary for a long time. ;))
     

Share This Page