Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I close a parent window in JS?? 1

Status
Not open for further replies.

ZooLee

Programmer
Jan 8, 2007
12
HU
Hi all,

Whatever reason I can not close the parent window in the new Mozilla firefox 2. I am getting the following message:

"Scripts may not close windows that were not opened by script"

All I need is somehow to close the parent, main window from JavaScript. It may sound very easy but I tried a bunch of common codes already and it did not work for the new Mozilla... Any help out there?
 
I think your error message already kinda gave you your answer: You can't do it. With older browser versions there were workarounds to window.close() - in IE7 you are always prompted for validation - in FF it just flat out does not work.

More than likely (I have not looked myself) there is a setting in FF or Mozilla that will enable you to programmatically close your browser window, but as you've seen it's turned off by default - which means that about 99.9% of all the other users probably have that setting turned off as well.

I'd just accept that it's not gonna be possible. Otherwise you're just beating a dead horse.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Unfortunately we do not have control on making the parent window a "script opened window". So we have a parent window and it does not close... Is there a way to override those default settings you wrote about somehow? It really sounds like a dead horse otherwise... It is just hard to believe there is no workaround for such a simple thing.
 
In the address bar of firefox type:

about:config

Scroll down to this option (they're in alphabetical order):

dom.allow_scripts_to_close_windows

The default value is set to false, double click the line to toggle the option on.



Now..... for the hardest part - convince EVERY user that comes to your site to follow those instructions, because unless they toggle that setting to true, your code will not function correctly. As far as a way to override that setting - why would the setting exist in the first place if you could just override it?

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
I was hoping that there is a programmatic way to override it... we are getting back to the dead horse again...
Thanks anyways!
 
Yeah, it's definitely a dead horse. FF added that option to prevent spammers and annoying scripts from closing the browser window when they'd stumble across the culprits' sites. Same thing with the status bar at the bottom of the page. It used to be a simple window.status = "blah" to change what was displayed there before, now programmers do not have the ability to change what text is displayed there unless the users modify their browser settings to allow it. Which almost never happens.

Thanks for the star [thumbsup2]

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
It used to be a simple window.status = "blah" to change what was displayed there before, now programmers do not have the ability to change what text is displayed there unless the users modify their browser settings to allow it.

not quite true kaht, I found that although IE has stopped window.status , you can still use self.status ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I'd expect that to be fixed with a future patch then. This code allows you to bypass the "this window is closing, click ok to confirm blah blah blah" message in IE6:

Code:
   top.opener = self;
   top.window.close();

But has since been fixed in IE7. It would probably be wise not to rely on functionality like self.status to give the user information on the status bar that they may potentially come to rely on. Once MS fixes that loophole your code will then cease to function, and you could potentially have clients that are upset or confused because they no longer see their status bar message. Then it looks bad on your behalf as if something has been broken - when in actuality you haven't changed a thing.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
i hear ya, but i usually use it to blank out the hover URL info, I don't like it showing javascript:blah blah or mycgi.cgi?urlvar&urlvar etc.. so i make it = '' on hover, I know shame on me!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Well, at least that degrades nicely. If it ever gets fixed they will start to see the anchor information - which shouldn't adversely affect anything [smile]

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top