百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>JS教程> js window open不被拦截的解决方法
分享文章到:

js window open不被拦截的解决方法

发布时间:01/15 来源: 浏览: 关键词:
今天在处理页面ajax请求过程中,想实现请求后打开新页面,就想到通过 js window.open 来实现,但是最终都被浏览器拦截了。

在谷歌搜索有没有解决方法,有些说可以通过新建a标签,模拟点击来实现,但是测试发现都实现不了,照样被浏览器拦截。

最后找到了一个折中的办法,可以实现新页面打开,但是没有a标签的那种直接流量新页面的效果。

实现代码:

 代码如下

$obj.click(function(){
 var newTab=window.open('about:blank');
 $.ajax({
  success:function(data){
   if(data){
    //window.open('http://www.111cn.net');
    newTab.location.href="http://www.111cn.net";
   }
  }
 })
})

其它方法

 代码如下

<script type="text/javascript">

<!-- 

$( 

function()

{

//方法一

window.showModalDialog("http://www.111cn.net/");

window.showModalDialog("http://www.111cn.net/");

 


//方法二

var aa=window.open();

setTimeout(function(){

aa.location="http://www.111cn.net";

}, 100);

 


var b=window.open();

setTimeout(function(){

b.location="http://www.111cn.net";

}, 200);

 


var c=window.open();

setTimeout(function(){

c.location="http://www.111cn.net";

}, 300);

 


var d=window.open();

setTimeout(function(){

d.location="http://www.111cn.net";

}, 400);

 


var ee=window.open();

setTimeout(function(){

ee.location="http://www.111cn.net";

}, 500);

 


var f=window.open();

setTimeout(function(){

f.location="http://www.111cn.net";

}, 600);

 


var g=window.open();

setTimeout(function(){

g.location="http://www.111cn.net";

}, 700);

 


var h=window.open();

setTimeout(function(){

h.location="http://www.111cn.net";

}, 800);

 


var i=window.open();

setTimeout(function(){

i.location="http://www.111cn.net";

}, 900);

 


var j=window.open();

setTimeout(function(){

j.location="http://www.111cn.net";

}, 1000);

 


//方法三

var a = $("<a href='http://www.111cn.net' target='_blank'>Apple</a>").get(0);

var e = document.createEvent('MouseEvents');

e.initEvent( 'click', true, true );

a.dispatchEvent(e);

 


var a = $("<a href='http://www.111cn.net' target='_blank'>Apple</a>").get(0);

var e = document.createEvent('MouseEvents');

e.initEvent( 'click', true, true );

a.dispatchEvent(e);

}

 

);

//-->

</script>

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有3人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板