Home >Web Front-end >JS Tutorial >InstantClick is compatible with MathJax, Baidu Statistics and other solutions
This article mainly introduces how to make InstantClick compatible with MathJax, Baidu Statistics, etc. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look.
Some netizens mentioned before that LaTex (implemented by MathJax) on the blog is broken. The reason is that instantclick is used here to achieve the effect of opening the web page in seconds. However, since instantclick will not re-run the JavaScript code located in the head area, many tool software, such as MathJax, Baidu Statistics, Google Analytics, Google Code Prettify and other software, directly insert JS files into the head area. This causes these tools to become invalid after instantclick and require reconfiguration.
The configuration is not complicated. The codes of these tools themselves do not need to be modified in any way, and they can be placed as you want. But add the following code before 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>
The meaning of this code is to implement MathJax through direct function calls every time the page is reloaded. , Baidu Statistics, Google Code Prettify, and re-run Google Analytics.
The above is the detailed content of InstantClick is compatible with MathJax, Baidu Statistics and other solutions. For more information, please follow other related articles on the PHP Chinese website!