AngularJS window.close无效

nat*_*ate 0 javascript angularjs

我在调用window.close函数时遇到问题,没有收到以下错误:

脚本可能只关闭由它打开的窗口.

以下是我的应用布局:

HTML:

<html ng-app="mynewAPP" ng-controller="appCTRL">

....blahblah </html>
Run Code Online (Sandbox Code Playgroud)

我的Angular控件工作正常,但是当我打电话时window.close,它不起作用(至少关闭部分...应用程序的其余部分很好).

app.controller("appCTRL" ,function( [injections]){
  $window.close();
}
Run Code Online (Sandbox Code Playgroud)

我如何允许AngularJS关闭它所在的窗口?

例如,下面的脚本可以正常工作:(基本的JS)

<html>
<head>
<script type="text/javascript">
    function closeme(){
        window.close(); 
    }

    </script></head>

    <body onload="closeme()"></body>
</html>
Run Code Online (Sandbox Code Playgroud)

对于那些想知道我如何打开页面的人,只需访问浏览器上的"mypage.html"即可.没有什么花哨.

Bil*_*lly 7

由于安全限制,您只能关闭window.close由javascript打开的窗口.

参考:MDN