Posted in Javascript onOctober 30, 2014
本文实例讲述了js实现window.open不被拦截的解决方法。分享给大家供大家参考。具体分析如下:
一、问题:
今天在处理页面ajax请求过程中,想实现请求后打开新页面,就想到通过 js window.open 来实现,但是最终都被浏览器拦截了。
二、分析:
在谷歌搜索有没有解决方法,有些说可以通过新建a标签,模拟点击来实现,但是测试发现都实现不了,照样被浏览器拦截。
最后找到了一个折中的办法,可以实现新页面打开,但是没有a标签的那种直接流量新页面的效果。
三、实现代码:
$obj.click(function(){ var newTab=window.open('about:blank'); $.ajax({ success:function(data){ if(data){ //window.open('https://3water.com'); newTab.location.href="https://3water.com"; } } }) })
其它方法:
<script type="text/javascript"> <!-- $( function() { //方法一 window.showModalDialog("https://3water.com/"); window.showModalDialog("https://3water.com/"); //方法二 var aa=window.open(); setTimeout(function(){ aa.location="https://3water.com"; }, 100); var b=window.open(); setTimeout(function(){ b.location="https://3water.com"; }, 200); var c=window.open(); setTimeout(function(){ c.location="https://3water.com"; }, 300); var d=window.open(); setTimeout(function(){ d.location="https://3water.com"; }, 400); var ee=window.open(); setTimeout(function(){ ee.location="https://3water.com"; }, 500); var f=window.open(); setTimeout(function(){ f.location="https://3water.com"; }, 600); var g=window.open(); setTimeout(function(){ g.location="https://3water.com"; }, 700); var h=window.open(); setTimeout(function(){ h.location="https://3water.com"; }, 800); var i=window.open(); setTimeout(function(){ i.location="https://3water.com"; }, 900); var j=window.open(); setTimeout(function(){ j.location="https://3water.com"; }, 1000); //方法三 var a = $("<a href='https://3water.com' target='_blank'>Apple</a>").get(0); var e = document.createEvent('MouseEvents'); e.initEvent( 'click', true, true ); a.dispatchEvent(e); var a = $("<a href='https://3water.com' target='_blank'>Apple</a>").get(0); var e = document.createEvent('MouseEvents'); e.initEvent( 'click', true, true ); a.dispatchEvent(e); } ); //--> </script>
希望本文所述对大家基于javascript的web程序设计有所帮助。
js实现window.open不被拦截的解决方法汇总
- Author -
shichen2014声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@