jQuery+ajax中,让window.open不被拦截(转)
方法1:
<input type="button" class="preview" value="预览"/>
$('.preview').live('click', function(){
var w = window.open();//发请求之前打开一个空页面
$.ajax({..., success:function(msg){
setTimeout(function(){w.location='http://www.baidu.com';}, 0);//0秒后给新窗口的localtion赋值
}});
});
方法2:
<input type="button" value="预览" onclick="if(preview()){window.open('http://www.baidu.com');}"/>
function preview(){
var bol = false;
$.ajax({async:false,...,success:function(msg){
if (msg == 1) {
bol = true;
} else {
bol = false;
}
}});
return bol;
}