js实现页面加载后自动刷新一次,仅一次

2022-08-01 14:37:07 浏览数 (1)

博客开启PJAX局部刷新Ajax导致文章的代码高亮插件第一次加载不会引用高亮模块需要再刷新一次,那么这段代码可以帮助你在加载完成后自动刷新一次,就解决了这个问题...

增加在主题的footer.php文件中即可..
代码语言:javascript复制
<script>
String.prototype.queryString = function(name) {
var reg = new RegExp("[?&]"   name   "=([^&] )", "i"),
    r = this.match(reg);
    return r !== null ? unescape(r[1]) : null
};
window.onload = function() {
    var last = location.href.queryString("_v");
    if (location.href.indexOf("?") == -1) {
        location.href = location.href   "?_v="   (new Date().getTime())
    } else {
        var now = new Date().getTime();
        if (!last) {
            location.href = location.href   "&_v="   (new Date().getTime())
        } else if (parseInt(last) < (now - 500)) {
            location.href = location.href.replace("_v="   last, "_v="   (new Date().getTime()))
        }
    }
};
</script>

0 人点赞