我有以下代码在Chrome中完美运行:点击New
,它会打开一个弹出窗口,然后点击Change
会导致重定向到另一个页面。
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
</head>
<body ng-controller="contentCtrl">
<button ng-click="openNew()">New</button>
<button ng-click="change()">Change</button>
<script>
var app = angular.module('plunker', []);
app.controller('contentCtrl', ['$scope', function ($scope) {
$scope.openNew = function () {
$scope.popup = window.open("https://www.stackoverflow.com", "popup", "status=1, location=1");
}
$scope.change = function () {
// $scope.popup = window.open("https://www.sina.com", "popup", "status=1, location=1");
// $scope.popup.location.assign("https://www.sina.com")
// $scope.popup.location.href("https://www.sina.com")
// $scope.popup.location = "https://www.sina.com"
$scope.popup.location.href = "https://www.sina.com"
}
}]);
</script>
</body>
</html>
但是,此代码在IE 11中不起作用。我发现this thread列出了IE中的几种重定向方式,我尝试了location.assign(...)
,location.href(...)
等等。工作
有谁知道如何在IE中实现window.open的重定向?
答案 0 :(得分:1)
根据documentation,window.location.href=
似乎是在IE中设置(和获取)窗口URL的最佳方式。
如果这不起作用,则替换应该执行操作:$scope.popup.location.replace("https://www.google.com/");