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

    Jul 19, 2010
    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.

    <script type="text/javascript">

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

    Mohan Reddy
  2. eponym macrumors 6502

    Jul 2, 2010
    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