zoukankan      html  css  js  c++  java
  • js 弹出新页面,避免被浏览器、ad拦截的一种办法

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

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

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

    <input type="search" id="keyword" value="" autocomplete="off" placeholder="请输入搜索关键字" />
            <a href="###" id="submit" 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方式提交表单等

  • 相关阅读:
    R set.seed()
    R tapply()
    R table
    清除R console中出现加号+
    r向量映射
    Java常识1
    IDEA配置
    SQL.字符串重叠项数量统计
    SQL.数据库内拆分字符串并返回数据表
    IDEA--TomCat配置
  • 原文地址:https://www.cnblogs.com/henryli/p/3701576.html
Copyright © 2011-2022 走看看