之前有網友提及博客上的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的重新運行。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。
新聞熱點
疑難解答
圖片精選