今天在開發支付寶在線支付接口時,使用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");