Close window from within a view in AngularJS

2.5k Views Asked by At

I'm trying to close a window from within a view in AnglarJS but I'm getting this error:

Scripts may close only the windows that were opened by it.

This is the script in 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();
        };
    });

and this is main.html:

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

I'm aware that from the latest working spec for window.close():

The close() method on Window objects should, if all the following conditions are met, close the browsing context A:

  • The corresponding browsing context A is script-closable.
  • The browsing context of the incumbent script is familiar with the browsing context A.
  • The browsing context of the incumbent script is allowed to navigate the browsing context A.

But how come that I'm getting this? Am I not within the same context?! And how to fix that?

Thanks.

0

There are 0 best solutions below