Home > Web Front-end > JS Tutorial > How to set up InstantClick to be compatible with MathJax, Baidu Statistics, etc.

How to set up InstantClick to be compatible with MathJax, Baidu Statistics, etc.

php中世界最好的语言
Release: 2018-04-17 16:55:10
Original
1554 people have browsed it

This time I will show you how to set up InstantClick to be compatible with MathJax and Baidu Statistics, etc. What are the precautions for setting up InstantClick to be compatible with MathJax and Baidu Statistics, etc. The following is a practical case, let's 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 section, many tool software, such as MathJax, Baidu Statistics, Google Analytics, Google Code Software such as Prettify directly inserts JS files into the head area. This causes these tools to become invalid after instantclick and require reconfiguration.

The configuration is not complicated, and the codes of these tools themselves do not need to be modified in any way. 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>
Copy after login

The meaning of this code is that every time the page is reloaded , MathJax, Baidu Statistics, Google Code Prettify, and Google Analytics are re-run through direct function calls.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:



The above is the detailed content of How to set up InstantClick to be compatible with MathJax, Baidu Statistics, etc.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template