我已经设置了 ng-click 网页中的图像。在 ng-click 处理程序中,我使用
ServiceData.getProductDetails(product).then(function(data) {
$scope.url = data;
var win = window.open($scope.url, '_blank');
win.focus();
});
getProductDetails: function(product) {
var promiseProductDetails;
if (productDetailsArr[product.id] == undefined) {
var ajaxUrl = productsByIDarray[product.id]['detailsview'];
try {
// $http returns a promise, which has a then function, which also returns a promise
promiseProductDetails = $http.get(ajaxUrl).then(function(response) {
return response;
});
} catch(err) {
}
// Return the promise to the controller
return promiseProductDetails;
} else {
var deferred = $q.defer();
deferred.resolve(productDetailsArr[product.id][url]);
return deferred.promise;
}
}
因此,单击会启动 ajax 调用来获取用户应该访问的 URL(目标 URL 是动态的)。我已经使用 Angular Promise 将 ajax 调用作为同步调用。这会导致 Web 浏览器将其视为不受信任并阻止弹出窗口。我不想将 img 标签与 html 中的锚定标签一起括起来。我有任何选项可以避免弹出窗口拦截程序吗?
最佳答案
将 ajax 调用移至用户与页面交互的早期点是解决此问题的解决方案。
关于javascript - 在图像上的新选项卡中打开链接,单击 Angular 而不使用弹出窗口拦截器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31508005/