判断页面是在移动端还是PC端打开的

$(function () {

  var curWwwPath = window.document.location.href;
  var pathName = window.document.location.pathname;
  var pos = curWwwPath.indexOf(pathName);
  var localhostPaht = curWwwPath.substring(0, pos);
  var host = window.location.host;
  var sUserAgent= navigator.userAgent.toLowerCase();
  var bIsIpad= sUserAgent.match(/ipad/i) == "ipad";
  var bIsIphoneOs= sUserAgent.match(/iphone os/i) == "iphone os";
  var bIsMidp= sUserAgent.match(/midp/i) == "midp";
  var bIsUc7= sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
  var bIsUc= sUserAgent.match(/ucweb/i) == "ucweb";
  var bIsAndroid= sUserAgent.match(/android/i) == "android";
  var bIsCE= sUserAgent.match(/windows ce/i) == "windows ce";
  var bIsWM= sUserAgent.match(/windows mobile/i) == "windows mobile";

  if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
    //mobile
      if ((localhostPaht +"//"+host) != ‘https://m.meiwo.cn‘){
         window.location.href = ‘https://m.meiwo.cn‘;
    }
    } else {
    //pc
      if ((localhostPaht +"//" +host) != ‘https://www.meiwo.cn‘){
          window.location.href = ‘https://www.meiwo.cn‘;
    }
  }

})

window.location.href = /Android|webOS|iPhone|iPad|BlackBerry/i.test(navigator.userAgent) ? "https://www.baidu.com/" :  "http://news.baidu.com/";或
if(/Android|webOS|iPhone|iPad|BlackBerry/i.test(navigator.userAgent)) {
    window.location.href = "https://www.baidu.com/";
} else {
    window.location.href = "http://news.baidu.com/";
}

原文地址:https://www.cnblogs.com/Loveonely/p/8508901.html

时间: 2024-07-31 20:08:46

判断页面是在移动端还是PC端打开的的相关文章

JavaScript判断移动端及pc端访问不同的网站

http://www.html-js.com/article/2677 现在很多网站都是分为两个版本,一个pc端的一个移动端的(响应式除外),针对这两个版本,就需要对访问的设备进行判断,如果是pc,就直接访问pc网站,否则就访问移动端网站. 对于这个问题可以通过判断UA来解决,前端js可以判断,后端判断也行,这里我们主要讨论的是如何通过js来处理. 假如我们有一个网站,pc端通过www.test.com访问,而移动端通过m.test.com来访问.我们需要做的就是当移动端访问www.test.c

js判断是移动端还是pc端

运行页面的时候,执行到js会判断来自于移动端还是pc端,如果是移动端则跳转制定链接地址,这样在手机端会有额外的不必要浪费的加载时间 var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return {//移动终端浏览器版本信息 trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto')

js判断移动端还是PC端

function isMobile(){ var sUserAgent= navigator.userAgent.toLowerCase(), bIsIpad= sUserAgent.match(/ipad/i) == "ipad", bIsIphoneOs= sUserAgent.match(/iphone os/i) == "iphone os", bIsMidp= sUserAgent.match(/midp/i) == "midp", b

js判断游览器是移动端还是PC端

js判断网页游览器是移动端还是PC端 1 <script type="text/javascript"> 2 function browserRedirect() { 3 var sUserAgent = navigator.userAgent.toLowerCase(); 4 var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; 5 var bIsIphoneOs = sUserAgent.match(/

判断是移动端还是PC端

// 判断是移动端还是PC端 $http_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']): ''; $http_accept = isset($_SERVER['HTTP_ACCEPT']) ? strtolower($_SERVER['HTTP_ACCEPT']): ''; $pos_hua = strpos($http_user_agent, 'mobi');

移动端访问PC端网页时跳转到对应的移动端网页

不想通过CSS自适应在PC端和移动端分别显示不同的样式,那么只能通过在移动端访问PC端网页时跳转到对应的移动端网页了,那么怎么跳转呢,网上也有很多文章说明,下面是本人测试有效的方式. 1.效果图 PC端访问显示: 移动端访问显示: 2.实现: 不考虑移动端搜索引擎优化的话,只需要通过JS判断是否移动端,然后确定是否跳转到指定页面就行了,主要JS如下: //判断是否移动端,如果是则跳转到指定的URL地址 function browserRedirect(url) { //只读的字符串,声明了浏览器

检测当前运行环境——移动端与PC端。

方法1: $(function checkBrowser(){ var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return { //移动终端浏览器版本信息 trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto') > -1, //opera内核 webKit: u.index

iis 如何搭建url 重定向,实现无线端和pc端不同的跳转

第一步,下载安装ARR(Application Request Routing), http://www.iis.net/downloads/microsoft/application-request-routing 第二步,简要设置ARR: 安装完成后,IIS里会多出两个图标,分别是Application Request Routing和URL重写.2.0版本(也就是2008或者Win7系统)需要双击ApplicationRequest Routing以后,在右侧Server Proxy Se

前端:移动端和PC端的区别

在阿里的几次面试中,总是被问到移动端和PC端有什么区别,当时回答的时候主要是回答了在兼容性.网速.适配.页面布局等方面的不同,但是还是很不系统,所以这里做一个总结. 第一: PC考虑的是浏览器的兼容性,而移动端开发考虑的更多的是手机兼容性,因为目前不管是android手机还是ios手机,一般浏览器使用的都是webkit内核,所以说做移动端开发,更多考虑的应该是手机分辨率的适配,和不同操作系统的略微差异化. 第二: 在部分事件的处理上,移动端多出来的事件是触屏事件,而缺少的是hover事件. 另外

关于移动端和PC端的交互的区别

对于现在的移动端设备的普及,移动端上的用户体验成了一个重要的关注点. 看了一些网上的关于移动端的交互和用户体验的知识,这里总结了一些.若有不足的地方,希望大家能够积极补充. PC端和移动端的产品的设计区别 屏幕与适配的问题考虑: 操作系统(windows,mac,android,iOS等)的区别: 网络环境(并不是每一个移动端设备随时随地都有网络): 使用场景(站着,坐着,躺着,蹲着,趴着,走着等等): 传感器的使用(摇一摇功能,地图实时导航,语音输入等): 操作方式不同(PC端是点击,移动端是