Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-01-23
5
Medium Priority
?
5,069 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 1600 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 400 total points
ID: 39813505
Mozilla Firefox doesn't support any scripts to close the current tab/window.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

721 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