unplugged_web Posted October 25, 2007 Share Posted October 25, 2007 I have two pieces of JavaScript that only seem to work in Safari, but I don't know why.The first snippet it <script type="text/javascript">function resizeWindow(){top.resizeTo(715,605)}</script></head><body onLoad="resizeWindow();"> and the second snippet it <a href="java script:;" onClick="java script:top.window.close();"><h5>Close</h5></a> They both work in Safari, but neither of them worked when I tested it in Firefox or IE (both of which have JavaScript enabled).Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted October 25, 2007 Share Posted October 25, 2007 The "top" object in Javascript is only supposed to be there when you are using frames. Since you have a body tag, it doesn't look like you're using frames. Use window.resizeTo for the first one, and window.close for the second one. Technically this shouldn't work in Safari either. Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 26, 2007 Share Posted October 26, 2007 java script: isn't needed (might not be allowed) here: onClick="java script:top.window.close();" justsomeguy, top is universal to all windows, and used in the case of an iframe. Since, in frame-less, iframe-less situations, it's equivalent to the window itself, I think this is an appropriate precaution. (Although, for the sake of cleanness, I would take out the confusing and redundant .window.) Link to comment Share on other sites More sharing options...
Reg Edit Posted October 26, 2007 Share Posted October 26, 2007 I have two pieces of JavaScript that only seem to work in Safari, but I don't know why.The first snippet it<script type="text/javascript">function resizeWindow(){top.resizeTo(715,605)}</script></head><body onLoad="resizeWindow();"> [...] Actually this one does work for me, in IE6, IE7 and FF. Try it in isolation from the rest of your html. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 26, 2007 Author Share Posted October 26, 2007 I changed <a href="java script:;" onClick="java script:top.window.close();"><h5>Close</h5></a> to <a href="java script:;" onClick="top.window.close();"><h5>Close</h5></a> but that still didn't seem to work in other browsers. Could it just be my computer?Thanks for help everyone.The other bit of code is now working so thanks for that. Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 26, 2007 Share Posted October 26, 2007 Do you dynamically open the window? When I use window.close() in Firefox, it tells me: Scripts may not close windows that were not opened by script.Internet Explorer asks the user, then closes the window on "Yes", and Opera complies with the script (my least favorite way to deal with the issue), though possibly not if it comes from a frame or iframe.Also, (just to make sure) is the above code your entire page? It's not a complete HTML document. Link to comment Share on other sites More sharing options...
unplugged_web Posted October 29, 2007 Author Share Posted October 29, 2007 Thanks for that. No that's not all of the code, I just coded that part of it. Thanks for pointing it out though - I have made that mistake in the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.