关闭未使用JavaScript脚本打开的窗口 [英] Close windows that were not opened by script using javascript

查看:186
本文介绍了关闭未使用JavaScript脚本打开的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的web应用程序在没有菜单栏,地址栏等的窗口中运行。我有一个Default.html页面,在这个页面中,我点击一个运行应用程序按钮,首先在另一个窗口中打开我的应用程序,使用 window.open ,然后通过使用 window.open 打开AutoClose.html来关闭当前窗口。 c> _self parameter

Default.html

 < HTML> 
< head>
< script type =text / javascript>
函数runApp(){
//打开我的应用程序
window.open('Application.html',null,'status:no; dialogHide:true; help:no; scroll:yes ;中心=是;');

//关闭此窗口
window.open('AutoClose.html','_self');
}
< / script>
< / head>
< body>
< input type =buttonvalue =运行应用程序onclick =runApp(); />
< / body>
< / html>

AutoClose.html

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

我的应用程序应该支持IE,Firefox和Chrome,我的代码在IE和Chrome上运行良好,无法关闭Firefox的第一个窗口,因为脚本可能无法关闭未由脚本打开的窗口警告。在Firefox上它会打开AutoClose.html,但是在这个页面中调用 window.close()只会导致脚本不能关闭没有被脚本打开的窗口警告和窗口没有关闭。顺便说一句,我的应用程序窗口打开没有任何问题(没有问题)。

看来,使用 window.open() code>与 _self 参数技巧对Firefox不起作用。因为我的目标是在没有菜单栏,地址栏等的窗口中运行应用程序。


  1. 有没有什么办法隐藏地址栏,菜单栏而不使用 window.open()(至少在Firefox中)?那么我不需要运行 window.close()

  2. 是否有任何设置可以禁止脚本不能关闭不是由脚本打开Firefox的警告? 允许脚本关闭未被脚本打开的窗口设置将会很好(

  3. 是否有任何方法使 window.close() code>工作在Firefox上没有使用JavaScript脚本打开的窗口

  4. 还有,还有其他的建议吗(

在此先感谢。

更新:这是一个银行应用程序,我只是一个开发者而不是决策者换句话说,某种分析师希望应用程序以这种方式工作,而我并没有质疑它,所以你所要做的全部是完全错误的答案不会真的有用。 $ b

解决方案

您无法关闭Firefox中的当前窗口,因为您没有打开它,无需将AutoClose.html加载到该窗口中。

但是,这整个业务与Windows是没有意义的。大多数人有他们的浏览器设置为在一个新的标签打开新的窗口,你不能阻止菜单栏等等。



如果您只是因为使用了您的应用程序而关闭了我的窗口,我个人就会非常恼火。 b

这可能是用户打开的唯一窗口 - 在这种情况下,您只是关闭了浏览器。这可能是他们想要按回来,关闭选项卡会惹恼他们。

从Firefox的这个错误是正确的,如果它在Chrome中工作,这是一个严重的错误,你应该报告它。


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.

解决方案

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.

这篇关于关闭未使用JavaScript脚本打开的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆