Jump to content

JavaScript not working


unplugged_web
 Share

Recommended Posts

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

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

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

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...