Home > Web Front-end > JS Tutorial > body text

How to determine whether the page is opened on PC or mobile through js

不言
Release: 2018-07-14 17:55:45
Original
2840 people have browsed it

This article mainly introduces the js judgment page whether to open on the PC or the mobile side. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

The js judgment page is in Whether it is opened on PC or mobile, it will jump to different index.html

window.addEventListener('load', function() {
      // true为手机,false为pc
      if (!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/)) {
           //跳转到移动端
           window.location.href = window.location.href.concat('m/');
      } else if (!navigator.userAgent.match(/AppleWebKit.*Mobile.*/)) {
          //跳转至pc端
           window.location.href = window.location.href.concat('pc/');
      }
})
Copy after login

. The above is the entire content of this article. I hope it will be helpful to everyone's study. , please pay attention to the PHP Chinese website for more related content!

Related recommendations:

Detailed explanation of js scope

Analysis of js function declaration and function expression

The above is the detailed content of How to determine whether the page is opened on PC or mobile through js. 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