11

I want my web application to run in a window which has no menubar, addressbar etc. I have a Default.html page and in this page I click a "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 on IE and Chrome but it is unable to close the first window on Firefox because of "Scripts may not close windows that were not opened by script" warning. On Firefox it opens the AutoClose.html but window.close() call in this page just causes the "Scripts may not close windows that were not opened by script" warning and window is not closed. By the way my application window is opened without any issues (no problem about that).

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

  1. Is there any way for hiding addressbar, menubar without using window.open() (at least for Firefox)? Then I will not need to run window.close()
  2. Is there any setting to suppress "Scripts may not close windows that were not opened by script" warning on Firefox? An "Allow scripts to close windows that were not opened by script" setting would be great (:
  3. Is there any way to make window.close() work for "windows that were not opened by script using javascript" on Firefox?
  4. Or, is there any other suggestions (:

Thanks in advance.

UPDATE: This is a banking application and I am just a developer not the decision maker. In other words some kind of analyst wants the application work in this way. And I am not questioning it. So "the whole thing you are trying to do is completely wrong" answers will not be really helpful.

Mehmet Ataş
  • 11,081
  • 6
  • 51
  • 78
  • 1
    Afaik you are SOL - but I also have a hard time seeing any need for this. If you ever succeed I would never again visit you DOS site – mplungjan Sep 07 '12 at 08:53
  • 2
    personal advice, dont do the "run in a window which has no menubar, addressbar". This is just annoying like hell. Those bars are useful and I barely see any good reason to deprive your users from their functionalities. – BiAiB Sep 07 '12 at 09:03

4 Answers4

13

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

But this whole business with windows is pointless. Most people have their browser set to open new windows in a new tab, and you can't prevent the menubar etc in a tab window.

I, personally, would be very irritated if you closed my window just because I used your application.

It could be the only window the user has open - in which case you just closed their browser. It could be they want to press back, and closing the tab will annoy them.

This error from firefox is correct, and if it works in Chrome that's a serious bug and you should report it.

Ariel
  • 25,995
  • 5
  • 59
  • 69
  • 1
    As I stated above my goal is "runnig the application in a window without menubar, addressbar etc." not closing the window. – Mehmet Ataş Sep 07 '12 at 09:00
  • So then just open a new window, and leave the current window alone. What is the problem? – Ariel Sep 07 '12 at 09:01
  • Beacuse the current page is the login page. And people would be very irritated if it is left there after login. – Mehmet Ataş Sep 07 '12 at 09:07
  • 1
    @MehmetAtaş So replace the login form with something else - just `display: none;` on it with css. – Ariel Sep 07 '12 at 10:03
  • @Waltzy How can I a open a new window with no adressbar without window.open. User just double clicks the Firefox shortcut, and types the address for login page. – Mehmet Ataş Sep 07 '12 at 10:23
  • @Ariel That is the issue already. After login AutoClose.html page, which has an empty html body, is opened in current window instead of Login page. Which means (on Firefox) after logon, user has two windows where first window displays an empty document (AutoClose.html) and second is my application. – Mehmet Ataş Sep 07 '12 at 10:28
  • 1
    @MehmetAtaş And? What's the problem with that? Just put some placeholder there and ignore it. Personally I don't think you should open a new window anyway - users find it VERY annoying. – Ariel Sep 07 '12 at 11:00
  • I do not care if someone finds it annoying or someone falls in love with it. I just want my application to run in a window without address and menu bars. On the other hand, in practice "the users", who will actually use the application, will not notice that i have opened a new window. – Mehmet Ataş Sep 07 '12 at 11:09
  • 1
    @MehmetAtaş Do what you wish, but you can not close the original window and there is nothing you can do about that - the browser will not let you. You will have to figure out what to put there. I suggest forgetting the new window, but you don't want to. Fine. But don't fight the impossible. And again, remember: Most of the time your attempt to open a window will be pointless since virtually all browsers just put new windows in a new tab. Making the entire exercise completely unnecessary. – Ariel Sep 07 '12 at 11:35
8

Simply,

open(location, '_self').close();
sampathsris
  • 21,564
  • 12
  • 71
  • 98
patrick
  • 113
  • 1
  • 2
1

The basic problem is that what your requirements-setter wants you to do is explicitly blocked by Firefox:

  1. There is no way to hide the UI in a user's existing browser window, because it's user-hostile and a favorite tool of phishers.
  2. There is no way to close the user's existing window from script, losing all the user's session history in the process.

Basically, the user has other things in the browser than just your bank thing. So assuming otherwise is more or less doomed to failure.

Is there any way you can push back on the unreasonable requirements?

Boris Zbarsky
  • 34,758
  • 5
  • 52
  • 55
  • It would be better if browsers let more customization on trust levels. I wish users were able to say browser something like "I trust this web site so allow it to do anything it wants with javascript" – Mehmet Ataş Sep 07 '12 at 12:39
  • Except of course no sane user should trust a typical bank website that way... In particular, if a user trusted the site described above, the site would then proceed to abuse that trust by destroying the user's session history! – Boris Zbarsky Sep 07 '12 at 13:36
  • Since it's an intranet web application used by employees of the bank considering these kind of scenarios seems so paranoid. – Mehmet Ataş Sep 07 '12 at 14:31
  • 5
    If it's an intranet application and you have a captive user audience, you can just make them all set the `dom.allow_scripts_to_close_windows` preference. But note that you _will_ be destroying their session history if they use this browser for anything other than your application. – Boris Zbarsky Sep 07 '12 at 17:25
0

This worked for me.

I used it to close the window when clicking a button in jQuery UI Dialog.

open(location, '_self').close();
sampathsris
  • 21,564
  • 12
  • 71
  • 98
Jan
  • 39
  • 1