Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can i check if the text is an Isogram ? 2 26
how can i Return this word's max repeat count? 2 18
Passport Expiry 3 44
Save ms data to server side. 19 43
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
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.
The viewer will learn how to dynamically set the form action using jQuery.
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…

773 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