Home  >  Article  >  Web Front-end  >  InstantClick is compatible with MathJax, Baidu Statistics and other solutions

InstantClick is compatible with MathJax, Baidu Statistics and other solutions

巴扎黑
巴扎黑Original
2017-09-13 09:35:441178browse

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(&#39;change&#39;, function(isInitialLoad) {
 if (isInitialLoad === false) {
  if (typeof MathJax !== &#39;undefined&#39;) // support MathJax
   MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
  if (typeof prettyPrint !== &#39;undefined&#39;) // support google code prettify
   prettyPrint();
  if (typeof _hmt !== &#39;undefined&#39;) // support 百度统计
   _hmt.push([&#39;_trackPageview&#39;, location.pathname + location.search]);
  if (typeof ga !== &#39;undefined&#39;) // support google analytics
    ga(&#39;send&#39;, &#39;pageview&#39;, 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn