2017-06-05 203 views
0

我有以下代码在Chrome中完美工作:点击New,它打开一个弹出窗口,然后点击Change导致重定向到另一个页面。window.open()的重定向在IE中不起作用

JSBin

<!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的重定向?

回答

1

根据documentation,window.location.href=似乎是在IE中设置(并获取)窗口URL的最佳方式。

如果这不起作用,替换应该做的伎俩:$scope.popup.location.replace("https://www.google.com/");

+0

太棒了!它的工作原理:https://plnkr.co/edit/dWT0kBNHSNgq134C6Sd4?p=preview – Thomas

+0

很高兴听到;) – nitobuendia