Solved

How to close current tab in a browser window fire fox version 26

Posted on 2014-01-23
5
4,676 Views
Last Modified: 2014-01-31
How to close current tab in a browser window? the below code is not working in firefox version 26. It is working properly in chrome version 32.

<html>
<head>
<script language="javascript" type="text/javascript">
function closeWindow() {
window.open('','_parent','');
window.close();
}
</script>
</head>
<body>
<a href="javascript:closeWindow();">Close Window</a>
</body>
</html>
0
Comment
Question by:Rocking
  • 3
5 Comments
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39803870
According to this thread on the Mozilla support forum you can only close windows you opened (and hence own):
https://support.mozilla.org/en-US/questions/966137
0
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39803898
This should work (but will prompt the user since you're asking for increased permissions:
function closeWindow() { 
    if (window.netscape) {netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");}
    window.open('','_parent',''); 
    window.close(); 
}

Open in new window

0
 
LVL 11

Accepted Solution

by:
Angelp1ay earned 400 total points
ID: 39803924
Here's the official documentation:
https://developer.mozilla.org/en-US/docs/Web/API/window.close?redirectlocale=en-US&redirectslug=DOM%2Fwindow.close
This method is only allowed to be called for windows that were opened by a script using the window.open method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

More of privilege escalation, quoted bit is probably important:
http://www-archive.mozilla.org/projects/security/components/signed-scripts.html#privs
Privileges are granted only in the scope of the requesting function. This scope includes any functions called by the requesting function. When the script leaves the requesting function, privileges no longer apply.

...and here's an interesting bit of discussion:
http://forums.mozillazine.org/viewtopic.php?t=527665
You might be able to request elevated privileges to close the window; that would be at the user's discretion. However, why do you need to close the window if your application did not open it?
Apparently, a loophole has been closed. :-D
0
 
LVL 58

Expert Comment

by:Gary
ID: 39803938
JavaScript is supposed to only be allowed to close windows that it opened itself
There is no point relying on hacky workarounds that will be probably stop working in the near future.
The above hack will not work in modern FF versions.
0
 
LVL 7

Assisted Solution

by:dimmergeek
dimmergeek earned 100 total points
ID: 39813505
Mozilla Firefox doesn't support any scripts to close the current tab/window.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

930 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

9 Experts available now in Live!

Get 1:1 Help Now