【发布时间】:2016-10-19 17:47:35
【问题描述】:
点击超链接时,
<a href="" ng-click="function(id)">{{id}}</a>
我需要根据我从 ajax 调用中获得的响应(例如,一个标志 - responseFlag)在新选项卡中打开一些内容。
我尝试了两种方法。
注意:函数依赖于 id,所以不要在页面加载时使用它。
1.
$http.get(url).success(function(response) {
if(response.data.responseFlag==true){
$window.open("http://www.example.com");
}
else{
//perform something else other that window.open
}
});
这里的问题是浏览器(Chrome、Mozilla)中的“弹出窗口阻止程序” - 一直阻止它们。
2.
var w = $window.open("","_blank");
$http.get(url).success(function(response) {
if(response.data.responseFlag == true){
w.location = "http://www.example.com";
}
else{
//perform something else
}
});
这里,如果'responseFlag = true',它会在新标签中打开。但正如您可能已经猜到的那样,对于“responseFlag = false”,选项卡也会打开。我也许可以在“其他”中使用 w.close() 。但我认为这不是解决方案。
朋友们帮帮我吧!
【问题讨论】:
标签: javascript angularjs ajax popup window.open