窗口拦截的处理方案:
1.window.open新窗口:
var newWindow=window.open('about_blank');
newWindow.document.writeln("<!DOCTYPE html>");
newWindow.document.writeln("<style type=\"text/css\">");
newWindow.document.writeln("body{background-color:#000}.status{position: absolute; width: 300px; height: 280px; left: 50%; top: 50%; margin-left: -150px; margin-top: -140px; z-index: 1;} .status-mg{width: 100%;} .status-mg img{display: block;width: 100%;} .spinner{width: 100px; height: 60px; text-align: center; font-size: 10px; margin-left: 88px; margin-top: 10px; } .spinner > div {margin-right:3px;background-color: #c4b689; height: 100%; width: 10px; display: inline-block; -webkit-animation: stretchdelay 1.2s infinite ease-in-out; animation: stretchdelay 1.2s infinite ease-in-out; } .spinner .rect2 { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; }.spinner .rect3 { -webkit-animation-delay: -1.0s; animation-delay: -1.0s; }.spinner .rect4 { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; }.spinner .rect5 { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; }@-webkit-keyframes stretchdelay { 0%, 40%, 100% { -webkit-transform: scaleY(0.4) } 20% { -webkit-transform: scaleY(1.0) } }@keyframes stretchdelay { 0%, 40%, 100% { transform: scaleY(0.4); -webkit-transform: scaleY(0.4); } 20% { transform: scaleY(1.0); -webkit-transform: scaleY(1.0); } }");
newWindow.document.writeln("</style>");
newWindow.document.writeln('<div class="status"><div class="status-mg"><img src="/pub/images/load-logo.png" alt="加载中..."></div><div class="spinner"><div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div><div class="rect5"></div></div></div>');
//window.open(url);
newWindow.location.href=url;
2.form表单提交新窗口:
var newWindow=window.open('about_blank');
newWindow.document.writeln("<!DOCTYPE html>"); //防止闪现404页面
//打开新窗口要在数据请求前
$.ajax({
type: 'POST',
url: XXX,
data: XXX,
success: function(res){
//type:支付类型。 1=直接跳转;2=表单提交;
if(res.data.type==1){
//直接打开链接
//window.open(res.data.url);
newWindow.location.href=res.data.url;
}
if(res.data.type==2){
//表单提交 直接提交submit()会被拦截
$('#online-pay-hide').html(res.data.list);
$.ajax({
type: 'POST',
url: $('#pay_form').attr('action'), //获取表单提交路径
data: $('#pay_form').serialize(), //获取表单数据
success: function(res){
newWindow.document.writeln(res); //根据返回res处理,此处返回html页面
}
});
}
}
})