admin管理员组文章数量:1389754
I'm working with Angularjs and I got a problem. The function $window.open(/somewhere) works perfect on pc browsers and mobile browser. But there's 1 case it doesn't work. Please help to look below:
$window.open(""); // OUTSIDE OF REQUEST - no problems
$https({
type: "GET",
url: "backendURL",
data: jsonData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$window.open(""); //This doesn't work.
},
error: function(msg) {
//alert(error);
}
});
Note that this is just happen with mobile browser : chrome and safari (I didn't test for others) So I think maybe someone has experience with this. Please please please help and advise.
Thanks ...
I'm working with Angularjs and I got a problem. The function $window.open(/somewhere) works perfect on pc browsers and mobile browser. But there's 1 case it doesn't work. Please help to look below:
$window.open("https://www.myurl."); // OUTSIDE OF REQUEST - no problems
$https({
type: "GET",
url: "backendURL",
data: jsonData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$window.open("https://www.myurl."); //This doesn't work.
},
error: function(msg) {
//alert(error);
}
});
Note that this is just happen with mobile browser : chrome and safari (I didn't test for others) So I think maybe someone has experience with this. Please please please help and advise.
Thanks ...
Share Improve this question asked Jan 7, 2016 at 1:54 Lại Công ThànhLại Công Thành 331 silver badge5 bronze badges 3-
What is with
$window
?? Pop Up blocker is probably blocking it. – epascarello Commented Jan 7, 2016 at 1:57 - hi bro, I already turn off the Pop up blocker :( still not work :( as I said, out side the request, it works perfect :( but inside, can not :( – Lại Công Thành Commented Jan 7, 2016 at 3:10
- I'm also facing the same issue right now. I got this very same issue in $.ajax request in normal javascript and got it fixed, but for angular I don't how to fix it. Tried the same way I do to normal js, didn't work. – Carrie Commented Jan 12, 2016 at 19:52
2 Answers
Reset to default 3I found this solution online, hope it will help you. do var win = window.open();
before the callback function, then inside .success
, change url by doing win.location = url;
. This should do the trick.
I think the overarching problem has to do with the "this" scope in JavaScript. If you are able to use arrow functionsfrom the ES6 version of JavaScript you can simply do
success: (msg)=>{
$window.open("https://www.myurl.");
}
I imagine most people will not have this option. In which case you can do something similar to what Yabin suggested:
//somewhere else in code.
var scopedWindow = $window;
//
success: function(msg){
scopedWindow.open("https://www.myurl.");
}
本文标签: javascriptAngular js windowopen not working in success for mobile browserStack Overflow
版权声明:本文标题:javascript - Angular js $window.open not working in .success for mobile browser - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744714607a2621327.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论