admin 管理员组文章数量: 1086019
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.
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.
Share Improve this question edited Dec 18, 2014 at 15:43 JJJ 33.2k20 gold badges94 silver badges103 bronze badges asked Dec 18, 2014 at 15:37 NateNate 1,7704 gold badges25 silver badges41 bronze badges 4- 3 The important part here is how you've opened the window, as the error message says. – JJJ Commented Dec 18, 2014 at 15:39
- 1 Just as a new browser (i.e by visiting mypage.html) – Nate Commented Dec 18, 2014 at 15:40
- 1 Then you can't close the window programmatically. The "basic JS" version would also not do it. – JJJ Commented Dec 18, 2014 at 15:41
- yes, this "basic js" does do it, as i have tested it.. in both IE and Chrome (FF doesnt close it) – Nate Commented Dec 18, 2014 at 15:42
1 Answer
Reset to default 7Due to security restriction you can only close windows with window.close
that were opened by javascript.
Reference: MDN
本文标签: javascriptAngularJS windowclose not workingStack Overflow
版权声明:本文标题:javascript - AngularJS window.close not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744037546a2522649.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论