详解如何让InstantClick兼容MathJax、百度统计等
之前有网友提及博客上的LaTex(由MathJax实现)坏掉了,其原因是这里使用了instantclick,以达到网页秒开的效果。但由于instantclick不会重新运行位于head部分的JavaScript代码,而很多工具性软件,比如MathJax、百度统计、GoogleAnalytics、GoogleCodePrettify等软件都是直接将JS文件插入到head区域。这导致这些工具在instantclick点击后失效,需要重新配置。
配置并不复杂,这些工具本身的代码不用做任何修改,该怎么放还怎么放。但在InstantClick.init();之前添加以下代码:
InstantClick.on('change',function(isInitialLoad){ if(isInitialLoad===false){ if(typeofMathJax!=='undefined')//supportMathJax MathJax.Hub.Queue(["Typeset",MathJax.Hub]); if(typeofprettyPrint!=='undefined')//supportgooglecodeprettify prettyPrint(); if(typeof_hmt!=='undefined')//support百度统计 _hmt.push(['_trackPageview',location.pathname+location.search]); if(typeofga!=='undefined')//supportgoogleanalytics ga('send','pageview',location.pathname+location.search); } }); InstantClick.init();
这段代码的含义是每次页面重载时,通过直接的函数调用来实现MathJax、百度统计、GoogleCodePrettify、GoogleAnalytics的重新运行。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
10 毛笔哥哥结婚祝福语简短
11 向国庆送祝福语简短
12 建队节祝福语简短
13 朋友喜得外孙简短祝福语
14 小店营业的祝福语简短
15 餐饮生日祝福语简短独特
16 鲜花英语祝福语卡片简短
17 男朋友暴富祝福语简短
18 婶婶拜年祝福语大全简短