Home  >  Article  >  Web Front-end  >  Introduction to the method of determining whether it is a mobile page using js

Introduction to the method of determining whether it is a mobile page using js

高洛峰
高洛峰Original
2017-03-19 09:55:591465browse

This article mainly introduces the js method to determine whether it is a mobile page. It has a very good reference value. Let’s take a look at it with the editor.

Without further ado, please look at the code:

<script>
if (/mobile/i.test(navigator.userAgent) || /android/i.test(navigator.userAgent)) document.body.classList.add(&#39;mobile&#39;);
window.addEventListener(&#39;load&#39;, function(event) {
 setTimeout(function () {
  hab(&#39;#sup-post-2&#39;);
  hab(&#39;#gd1-inner&#39;);
 }, 1000);
});
</script>


The above is the detailed content of Introduction to the method of determining whether it is a mobile page using js. 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