Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 588
  • Last Modified:

window.close() does not work in Firefox 2.0 upwards

Hi,
I have been trying to close a window using javascript and the window.close to no avail. I have found a few suggestions like:
. Copy/paste the following code to the head of your page…

<script language="javascript" type="text/javascript">

function closeWindow() {

window.open('','_parent','');

window.close();

}

</script>

2. Set your link like this:

<a href="javascript:closeWindow();">Close Window</a>

but that did not have any effect. So I am guessing it was for FF < 3.0 probably <2.0. I have also tried using window.focus() and self.close(). Also I am not trying to kill the window from a popup so it should not be a problem of javascript origin. Another 'solution' that failed was:
window.opener='';
window.close();
So does anybody know if there is a way of doing it or is it impossible?

0
schwago
Asked:
schwago
3 Solutions
 
Tomarse111Commented:
Are you trying to do this from the main window? i.e. not trying to close a popup and / or not trying to close the main window from a popup?
0
 
schwagoAuthor Commented:
Yes, I am trying to do this from a window I opened by hand and not with javascript. I get the error: a page not opened with javascript can not be closed with a script. I was wondering if it was possible to circunvent that.
0
 
Tomarse111Commented:
As far as I am aware the only windows you are allowed to close using javascript, are windows you have opened using javascript e.g. window.open() etc

Otherwise people could close your window at will, which could be incredibly annoying.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
amar31282Commented:
please set your firefox browser:

1.input "about:config " to your firefox address bar and enter;

2.make sure your "dom.allow_scripts_to_close_windows" is true



<script>
function closeMe()
{
var win=window.open("","_self");
win.close();
}
</script>
 
<html>
<body>
<form>
<input type="button" name="Close" onclick="closeMe()" />
</form>
</body>
</html>

Open in new window

0
 
amar31282Commented:
any update @schwago:

Regards,
Amarjit
0
 
swistCommented:
As far as I tested, for most browsers (includin ff2 & ff3, without need for changing browser conf.) this should work:
<input type="button" name="Close" onclick="javascript: window.opener = window.self; window.close();" />

Open in new window

0
 
kadabaCommented:
0
 
Michel PlungjanIT ExpertCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now