Solved

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

Posted on 2014-01-23
5
4,638 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

707 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

18 Experts available now in Live!

Get 1:1 Help Now