这次给大家带来instantclick怎么设置才能兼容mathjax与百度统计等,instantclick设置兼容mathjax与百度统计等的注意事项有哪些,下面就是实战案例,一起来看一下。
之前有网友提及博客上的latex(由mathjax实现)坏掉了,其原因是这里使用了instantclick,以达到网页秒开的效果。但由于instantclick不会重新运行位于head部分的javascript代码,而很多工具性软件,比如mathjax、百度统计、google
analytics、google code
prettify等软件都是直接将js文件插入到head区域。这导致这些工具在instantclick点击后失效,需要重新配置。
配置并不复杂,这些工具本身的代码不用做任何修改,该怎么放还怎么放。但在instantclick.init();之前添加以下代码:
<script data-no-instant>
instantclick.on('change', function(isinitialload) {
if (isinitialload === false) {
if (typeof mathjax !== 'undefined') // support mathjax
mathjax.hub.queue([typeset,mathjax.hub]);
if (typeof prettyprint !== 'undefined') // support google code prettify
prettyprint();
if (typeof _hmt !== 'undefined') // support 百度统计
_hmt.push(['_trackpageview', location.pathname + location.search]);
if (typeof ga !== 'undefined') // support google analytics
ga('send', 'pageview', location.pathname + location.search);
}
});
instantclick.init();
</script>
这段代码的含义是每次页面重载时,通过直接的函数调用来实现mathjax、百度统计、google code prettify、google analytics的重新运行。
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
以上就是instantclick怎么设置才能兼容mathjax与百度统计等的详细内容。