Close windows that have not been opened by script using javascript

I want my web application to run in a window that does not have a menu, address bar, etc. I have a Default.html page, and on this page I click the Run Application button, which first opens my application in another window using window.open and then closes the current window by opening "AutoClose.html" using window.open with _self parameter

Default.html

 <html> <head> <script type="text/javascript"> function runApp() { // Open my application window.open('Application.html', null, 'status:no;dialogHide:true;help:no;scroll:yes;center=yes;'); // Close this window window.open('AutoClose.html', '_self'); } </script> </head> <body> <input type="button" value="Run Application" onclick="runApp();" /> </body> </html> 

AutoClose.html

 <html> <head> <script type="text/javascript"> window.close(); </script> </head> <body></body> </html> 

My application should support IE, Firefox and Chrome, and my code works fine in IE and Chrome, but it cannot close the first window in Firefox due to the fact that "Scripts may not close windows that were not opened with a script" ., In Firefox, it opens a call to AutoClose.html, but window.close() on this page causes β€œScripts may not close windows that were not opened with a script,” and the window does not close. By the way, my application window is open without any problems (no problems with this).

It seems that using window.open() with the _self parameter trick does not work for Firefox. Since my goal is to run the application in a window without a menu, address bar, etc.

  • Is there a way to hide the address bar menu without using window.open() (at least for Firefox)? Then I will not need to run window.close()
  • Are there any settings to suppress "Scripts may not close windows that were not opened with a script" warning in Firefox? "Allowing scripts to close windows that were not opened with the script parameter" would be great (:
  • Is there a way to make window.close() work for "windows that were not opened with a script using javascript" in Firefox?
  • Or, are there any other suggestions (:

Thanks in advance.

UPDATE: This is a banking application, and I'm just a developer, not a decision maker. In other words, some analyst wants the application to work this way. And I do not ask about it. Therefore, "all you are trying to do is completely wrong," the answers will not be really helpful.

+6
source share
4 answers

You cannot close the current window in firefox because you did not open it. It doesn't matter that you loaded AutoClose.html into it.

But the whole thing with windows is pointless. Most people have their browser set to open new windows in a new tab, and you cannot ban the menu, etc. In the tabs window.

I personally would be very annoyed if you would close my window just because I used your application.

This may be the only window opened by the user - in this case, you just closed your browser. Perhaps they want to back off, and closing the tab will annoy them.

This error from firefox is correct, and if it works in Chrome, this is a serious error, and you should report it.

+6
source

Simply,

 open(location, '_self').close(); 
+5
source

The main problem is that your installer requirement wants you to do this, it is explicitly blocked by Firefox:

  • It is not possible to hide the user interface in the browser user window because it is a user enemy and a favorite phishing tool.
  • It is not possible to close an existing user window from a script, losing the entire history of user sessions in the process.

Basically, the user has other things in the browser than just the business of your bank. Thus, assuming that the other is more or less doomed to failure.

Is it possible to refuse unreasonable claims?

+1
source

It worked for me.

I used it to close the window when I clicked a button in the jQuery UI dialog box.

 open(location, '_self').close(); 
0
source

Source: https://habr.com/ru/post/924831/


All Articles