1

我正在尝试从 AngularJS 的视图中关闭一个窗口,但出现此错误:

脚本只能关闭它打开的窗口。

这是中的脚本index.html

    var app = angular.module('app', ['ngRoute']);
    app.config(function($routeProvider, $locationProvider) {
        $routeProvider
            .when('/', {templateUrl: 'main.html', controller: 'mainCtrl'})
            .otherwise({redirectTo: '/'});
    });
    app.controller('mainCtrl', function($scope, $route, $routeParams, $location, $window) {
        $scope.$route = $route;
        $scope.$location = $location;
        $scope.$routeParams = $routeParams;
        $scope.closeApp = function(){
                $window.close();
        };
    });

这是main.html

<button ng-click="closeApp()">Close this app please</button>

我知道从 window.close() 的最新工作规范中

如果满足以下所有条件,Window 对象的 close() 方法应该关闭浏览上下文 A:

  • 相应的浏览上下文 A 是可脚本关闭的。
  • 现任脚本的浏览上下文熟悉浏览上下文 A。
  • 现任脚本的浏览上下文被允许在浏览上下文 A 中导航。

但我怎么会得到这个?我不是在同一个上下文中吗?!以及如何解决这个问题?

谢谢。

4

0 回答 0