Nate
Nate

Reputation: 1750

AngularJS window.close not working

I'm having trouble calling the window.close function, without getting the following error:

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

Here is how I have my app laid out:

HTML:

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

....blahblah </html>

My Angular controls work fine, but when I call window.close, it is not working (at least the closing part... rest of app is fine).

app.controller("appCTRL" ,function( [injections]){
  $window.close();
}

How would I go about allowing AngularJS to close the window it is sitting on?

For example the below script would work fine: (basic JS)

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

    </script></head>

    <body onload="closeme()"></body>
</html>

For those that are wondering how I am opening the page, simply by visiting "mypage.html" on the browser. Nothing fancy.

Upvotes: 0

Views: 8583

Answers (1)

Billy
Billy

Reputation: 1104

Due to security restriction you can only close windows with window.close that were opened by javascript.

Reference: MDN

Upvotes: 7

Related Questions