Ad

Angular Js $window.open Not Working In .success For Mobile Browser

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.com");  // 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.com");  //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 ...

Ad

Answer

I 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.

Ad
source: stackoverflow.com
Ad