今天在开发支付宝在线支付接口时,使用window.open弹出新窗口完成支付,别的浏览器都是能够 的,可是在safari浏览器里面被阻挡。javascript
缘由是:safari 中没办法在回调函数里面执行window.openhtml
这里用到了jquery框架,如下是代码:java
$(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()以外,放在回调函数里面是跳不出来的。jquery
var newWindow = window.open("about:blank");