S@m Posted January 31, 2007 Share Posted January 31, 2007 ..search is not working at the moment, so please direct me if this has been covered already.I am working on closing a window (non-popup) with a text link. window.close(); But, as you know unless that window was opened w/ window.open(), you will get an alert message along the lines of "something is trying to close the window..."I did some looking around. Found this: window.opener='x';window.close(); Now, the explanation was that it (the browser) checks the value of "opener" if it is equal to nothing, then you get the error. So, if it equals something, the window will close.That I understand. Makes sense.My js skills are pretty "low" I can read/understand but when it comes to debugging...not so good.IE this script works fine. No problems.But Firefox, I get this:uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: java script:window.opener='x';window.close(); :: <TOP_LEVEL> :: line 1" data: no]I don't understand what it can't convert.I looked around for answers, but didn't come up with much.I have also tried the technique on interwebby: <script language="javascript" type="text/javascript">function closeWindow() {window.open('','_parent','');window.close();}</script> But again, fine in IE...not in FF.It seems to me that if I can force opener to equal something, then I should be good right?Any suggestions? Link to comment Share on other sites More sharing options...
aspnetguy Posted January 31, 2007 Share Posted January 31, 2007 Firefox appears to be alot smarter than IE. It is probably checking for an actual window object...Firefox may also make window.opener readonly which would mean you cannot set it. Link to comment Share on other sites More sharing options...
S@m Posted February 1, 2007 Author Share Posted February 1, 2007 I was afraid of the read only part.... Link to comment Share on other sites More sharing options...
aspnetguy Posted February 1, 2007 Share Posted February 1, 2007 the best I could come up with is if(document.all) window.opener = "x";window.close(); It works in IE, Opera closes the origianl tab and nothing happens in Firefox, not even a popup. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now