调用window.open()如果是用户点击操作,打开新窗口不被拦截
<script>
//如果在ajax回调函数中调用打开新窗口会被拦截
//如果是用户点击操作,打开新窗口不被拦截
//可以打开新窗口
document.getElementById('a').onclick = function () {
window.open('http://www.baidu.com');
return false;
};
//可以打开新窗口
function openwin() {
var url = "http://www.baidu.com";
var a = document.createElement("a");
a.setAttribute("href", url);
a.setAttribute("target", "_blank");
a.setAttribute("id", "openwin");
document.body.appendChild(a);
a.click();
}
</script>
但是如果是在ajax中调用的话,会被大部分浏览器屏蔽,下面是解决方法。
//Ajax 请求回调函数中打开新窗口
var w = window.open();
$.get('quickPay.do', function (data) {
w.location.href = 'data.url';
})

1万+

被折叠的 条评论
为什么被折叠?



