Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mohan.reddy

macrumors newbie
Original poster
Jul 19, 2010
1
0
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
 
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. ;))
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.