首页 > 语言 > JavaScript > 正文

js 弹出新页面避免被浏览器、ad拦截的一种新方法

2024-05-06 16:04:52
字体:
来源:转载
供稿:网友
本文为大家介绍了使用js弹出新页面同时避免被浏览器、ad拦截等,具体的实现方法如下,大家不妨参考参考

以绑定click弹窗的方式,改为普通的链接,即 a[target=_blank],在点击打开新窗口之前,修改其href。

绑定mousedown,鼠标点击执行完成前修改href。

绑定focus,保证tab切换+enter时替换href。

复制代码 代码如下:


<input type="search" value="" autocomplete="off" placeholder="请输入搜索关键字" />
<a href="###" target="_blank" >搜索</a>
<script type="text/javascript">
(function(document) {
var submit = document.getElementById('submit');
var keyword = document.getElementById('keyword');
var url = 'http://www.baidu.com/baidu?wd=';
submit.onfocus = submit.onmousedown = function() {
var href = url + escape(keyword.value);
if (href !== submit.href) {
submit.href = url + escape(keyword.value)
}
}

})(document);
</script>


ps:还可以在 在html代码中 以onclick dom 0级方式绑定 、target方式提交表单等
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选