代码描述:js防止window.open()函数 弹出窗口被拦截。js防止window.open()函数弹出窗口被拦截源码下载
很多时候在使用window.open()函数打开一个页面的时候会发现被浏览器给当做广告给拦截了,但是有时候也是好用的不会被拦击,下面就介绍一下如何防止window.open()函数弹出的窗口被拦截的现象。 代码实例:
<!DOCTYPE html><html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <script type="text/javascript"> window.open("https://www.51qianduan.com","antzone"); </script> </head> <body> <div id="antzone">弹出窗口会被拦击</div> </body> </html>
在上面的代码中,弹出的窗口会被绝大多数浏览器当做广告拦截,代码修改如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <script type="text/javascript"> window.onload=function(){ var olink=document.getElementById("thelink"); olink.onclick=function(){ window.open("https://www.51qianduan.com","antzone"); } } </script> </head> <body> <a href="#" id="thelink">查看效果</a> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能