今天在开发支付宝在线支付接口时,使用window.open弹出新窗口完成支付,别的浏览器都是可以 的,但是在safari浏览器里面被阻挡。
原因是:safari 中没办法在回调函数里面执行window.open
这里用到了jquery框架,以下是代码:
$(document).ready(function() {
$("#tobuy").click(function() {
var newWindow = window.open("about:blank",'', 'width=1000,height=850,scrollbars=yes,resizable=1');
if (newWindow == null || typeof(newWindow)=='undefined') alert("关闭您的弹出窗口拦截器!");
$.post("Order/gotoshop", {id:$("#orderid").html()}, function(result){
if(result.status == 1){
newWindow.location.href = 'http://www.baidu.com/pay/alipay.html?id='+result.id;
}else{
alert('生成订单出现错误');
}
});
});
});
</script>
这里面注意一定要把打开窗口的代码放在$.post()之外,放在回调函数里面是跳不出来的。
var newWindow = window.open("about:blank");