AD:看小说【69书吧】影视剧大全【网飞】

防UC浏览器,夸克浏览器转码,应对UC浏览器、夸克浏览器转码,UC浏览器、夸克浏览器转码解决办法

小说站防UC浏览器,夸克浏览器转码,应对UC浏览器、夸克浏览器转码,UC浏览器、夸克浏览器转码解决办法

看到一个小说站是这样防UC、夸克转码的,他的下一章 href 是空的“ <a id="next" href="">下一章</a>”。然后利用js的滚动事件修改 href 属性。正常浏览时必然会滚动页面,滚动页面就触发了修改 href的事件,对正常浏览是没有任何影响的。
原理:UC或夸克浏览器打开页面时会自动进入转码页面,但下滑加载下一章的时候会出现无法加载下一章的提示,这时就会出现返回源页面的提示。

注:能加载下一章就不会有上面的提示,一只在他的转码页面里。

html代码 (修改章节页模板chapter.html)


修改前

    <div class="nr_page">
         <table cellpadding="0" cellspacing="0">
             <tr>
                <td class="prev"><a id="pb_prev" href="{?if $preview_chapterid != ""?}/{?$shortid?}/{?$articleid?}/{?$preview_chapterid?}.html{?else?}/{?$shortid?}/{?$articleid?}/{?/if?}">上一章</a></td>
                <td class="mulu"><a id="pb_mulu" href="/{?$shortid?}/{?$articleid?}/">目录</a></td>
                <td class="next"><a id="pb_next" href="{?if $next_chapterid != ""?}/{?$shortid?}/{?$articleid?}/{?$next_chapterid?}.html{?else?}/{?$shortid?}/{?$articleid?}/{?/if?}">下一章</a></td>
            </tr>
        </table>
    </div>


修改后, 下一章的href属性为空

    <div class="nr_page">
         <table cellpadding="0" cellspacing="0">
             <tr>
                <td class="prev"><a id="pb_prev" href="{?if $preview_chapterid != ""?}/{?$shortid?}/{?$articleid?}/{?$preview_chapterid?}.html{?else?}/{?$shortid?}/{?$articleid?}/{?/if?}">上一章</a></td>
                <td class="mulu"><a id="pb_mulu" href="/{?$shortid?}/{?$articleid?}/">目录</a></td>
                <td class="next"><a id="pb_next" href="">下一章</a></td>
            </tr>
        </table>
    </div>
<script>
    var shortid = "{?$shortid?}", articleid = "{?$articleid?}",   next_chapterid = "{?$next_chapterid?}";
</script>
<script type="text/javascript" src="/js/xxx.js"></script><!--xxx.js 就是下面的js代码-->


js代码如下:

//下一章的url判断
if (next_chapterid !== "") {//判断是否有下一章
    var person = {
        tid: shortid,
        eid: articleid,
        nextid: next_chapterid,
        Namepageid: function() {
            return "/" + this.tid + "/" + this.eid + "/" + this.nextid + ".html"
        }
    }
} else {//没有直接回目录
    var person = {
        tid: shortid,
        eid: articleid,
        Namepageid: function() {
            return "/" + this.tid + "/" + this.eid + "/"
        }
    }
}
//下一章的url判断end

//滚动事件修改 href 属性
var url = person.Namepageid();
if (window.screen.availHeight >= document.body.clientHeight) {//没有滚动条直接修改href 属性
    document.getElementById("pb_next").setAttribute("href", ""+ url)
} else {
    var tur = true;
    function scrollBottomOrTop() {
        var clients = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
        var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
        var wholeHeight = document.documentElement.scrollHeight;
        if (clients + scrollTop >= wholeHeight - 500) {//滚动条距离底部500px时执行修改href 属性
            document.getElementById("pb_next").setAttribute("href", ""+ url)
        }
        if (scrollTop >= 300) {//文章内容向上滚动300px时修改href 属性
            document.getElementById("pb_next").setAttribute("href", ""+ url)
        }
        tur = true
    }
    window.onscroll = function() {//500毫秒只执行一次
        if (tur) {
            setTimeout(scrollBottomOrTop, 500);
            tur = false
        } else {}
    }
}
 

全网热文

赞 (0)