jQuery.ajax({ "type":"post", "url":"http://www.baidu.com", "success":function(rel){ if(rel.isSuccess){ window.open(rel.url,"_blank"); } } });
這個url請求成功后window.open(rel.url,"_blank");會被瀏覽器攔截,無法打開新窗口,如果把window.open()放在ajax外面,問題就迎刃而解,代碼如下:
var result=""; jQuery.ajax({ "type":"post", "url":"http://www.baidu.com", "success":function(rel){ if(rel.isSuccess){ result=rel.url; //window.open(rel.url,"_blank"); } } }); if(result.length>0){ window.open(result,"_blank"); }