Solved

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

Posted on 2014-01-23
5
4,870 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

734 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