gpt4 book ai didi

javascript - window.close如何以 Angular 关闭当前窗口

转载 作者:行者123 更新时间:2023-12-02 14:27:13 36 4
gpt4 key购买 nike

嗨,这是我当前的代码,一旦我取消弹出窗口,我就会弹出窗口,我必须关闭整个应用程序选项卡,这意味着窗口

<!doctype html>
<html ng-app="plunker">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.11/angular.js"></script>
<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.10.0.js"></script>
<script src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<script>
angular.module('plunker', ['ui.bootstrap']);
var ModalDemoCtrl = function ($scope, $modal, $log) {

/* Note: The hard coded user object has been commented out, as
it is now passed as an object parameter from the HTML template.
*/
/* $scope.user = {
user: 'name',
password: null
};*/

$scope.open = function (user) {
$scope.user = user;
$modal.open({
templateUrl: 'myModalContent.html',
backdrop: true,
windowClass: 'modal',
controller: function ($scope, $modalInstance, $log, user) {
$scope.user = user;
$scope.submit = function () {
$log.log('Submiting user info.');
$log.log(JSON.stringify(user));
$modalInstance.dismiss('cancel');
}
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
window.open('location', '_self', '');
window.close();
};
},
resolve: {
user: function () {
return $scope.user;
}
}
});
};
};
</script>

<div ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3>I'm a modal!</h3>
</div>
<form ng-submit="submit()">
<div class="modal-body">
<label>User name</label>
<input type="text" ng-model="user.user" />
<label>Password</label>
<input type="password" ng-model="user.password" />
</div>
<div class="modal-footer">
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
<input type="submit" class="btn primary-btn" value="Submit" />
</div>
</form>
</script>

<button class="btn" ng-click="open({user: 'username', password: 'password'})">Open me!</button>
<div ng-show="user.password">Got back from modal: {{ user | json}}</div>
</div>
</body>
</html>

此代码不起作用,请提供帮助

window.close() 不起作用

最佳答案

window.close 只会关闭应用程序打开的窗口,而不会关闭用户打开的窗口/选项卡。这意味着当用户访问您的网站时,他/她打开了窗口而不是您的应用程序。但是如果你使用 javascript 使用 window.open 打开一个新窗口,你可以使用 window.close 关闭。这样做是出于安全原因,并且内置在几乎所有最新的浏览器中。

关于javascript - window.close如何以 Angular 关闭当前窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38117023/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com