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

Posted on 2008-11-11
Last Modified: 2013-12-07
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() {'','_parent','');




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:
So does anybody know if there is a way of doing it or is it impossible?

Question by:schwago
    LVL 15

    Expert Comment

    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?

    Author Comment

    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.
    LVL 15

    Accepted Solution

    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. etc

    Otherwise people could close your window at will, which could be incredibly annoying.
    LVL 14

    Assisted Solution

    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

    function closeMe()
    <input type="button" name="Close" onclick="closeMe()" />

    Open in new window

    LVL 14

    Expert Comment

    any update @schwago:


    Expert Comment

    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

    LVL 22

    Assisted Solution

    LVL 75

    Expert Comment

    by:Michel Plungjan
    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Create Mobile App Prototypes with Adobe XD

    This is a project-based course: we go through all the steps of creating a prototype from start to finish, using all the tools and features currently available in Adobe XD. You can complete the course in less than a day, plus all project files and fonts are included.

    Now-a-days, indirectly, postal services have been replaced by email services. Yes, whenever we hear the word "email" a lot of people only think of gmail. Some people still think that email and gmail are one and the same thing :-). Let's see some …
    I recently found myself in a Corporate Situation where the client had requested blocking access to any and all websites except his own Domain? Easy? I am sure this would be your answer but their requirement was, this has to be done without using…
    Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
    How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now