FFan丶Blog / 部分JS效果 / / PC站跳转手机站JS

PC站跳转手机站JS

分类:部分JS效果 发布时间:2020-01-15 11:20:16来源:FFan丶Blog
一、PC站所有页面跳转同一手机页面 function is_mobile() { var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|...

一、PC站所有页面跳转同一手机页面

function is_mobile() {

var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|jigs browser|hiptop|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)/i;var u = navigator.userAgent;

var result = regex_match.exec(u);

if (null == result) {

return false

} else {

return true

}

}

if (is_mobile()) {

window.location.href = "http://手机站域名/?" + window.location.href;}

二、PC站页面跳转手机站页面一一对应

写法1:

var s=document.referrer;

var browser_class = navigator.userAgent;

var browser_class_name1 = browser_class.match("Mobile");var browser_class_name2 = browser_class.match("mobile");var location_url = window.location.href;

if (browser_class_name1 != null || browser_class_name2 != null){if (location_url.match("m\\.") == null){

var newhref = location_url.replace("www","m");window.location.href= newhref;

}

}

写法2:

function is_mobile() {

var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|jigs browser|hiptop|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)/i;var u = navigator.userAgent;

var result = regex_match.exec(u);

if (null == result) {

return false

} else {

return true

}

}

if (is_mobile()) {

var s = window.location.href;

ss = s.split("/");

if (ss[3] == null || ss[3] == "") {

window.location.href = "http://手机站域名/";

} else if (ss[4] == null || ss[4] == "") {

window.location.href = "http://手机站域名/" + ss[3] + "/";} else {

window.location.href = "http://手机站域名/" + ss[3] + "/" + ss[4];}

}

三、PC站与手机站相互跳转对应页面

写法1:

var isPC = function () {

var userAgentInfo = navigator.userAgent.toLowerCase();var Agents = new Array("android", "iphone", "symbianOS", "windows phone", "ipad", "ipod");var flag = true;

for (var v = 0; v < Agents.length; v++) {

if (userAgentInfo.indexOf(Agents[v]) > 0) {

flag = false;

break;

}

}

return flag;

}

var pcUlr = "http://PC站域名";

var mobleUlr = "http://手机站域名";

if (isPC() && window.location.href.indexOf(mobleUlr) != -1) {window.location.href = pcUlr + GetUrlRelativePath()} else if (!isPC() && window.location.href.indexOf(pcUlr) != -1) {window.location.href = mobleUlr + GetUrlRelativePath()}

function GetUrlRelativePath() {

var url = document.location.toString();

var arrUrl = url.split("//");

var start = arrUrl[1].indexOf("/");

var relUrl = arrUrl[1].substring(start); 

if (relUrl.indexOf("?") != -1) {

relUrl = relUrl.split("?")[0];

}

return relUrl;

}

写法2:

PC端:if((navigator.userAgent.match(/(phone|pad|pod|mobile|ios|android|BlackBerry|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|symbian|transcoder)/i))){window.location = window.location.href.replace(/www./, 'm.');}

手机端:if(!(navigator.userAgent.match(/(phone|pad|pod|mobile|ios|android|BlackBerry|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|symbian|transcoder)/i)) && window.location.href.match(/(http[s]*:\/\/)m(ip)*\./)){window.location.href=window.location.href.replace(/(http[s]*:\/\/)m(ip)*\./, '$1www.');}

上一篇:没有了

下一篇:网站底部版权信息JS显示最新年份

猜你喜欢

  • 根目录新建.htaccess文件 RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\\. RewriteCond %{HTTP_HOST} !^$

    SEO2020-01-15
  • 一、PC站所有页面跳转同一手机页面 function is_mobile() { var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|

    部分JS效果2020-01-15
  • 快速把excel合并在一起,方便分析和统计可以利用excel表的宏计算就可以实现。方法如下: 1、我们需要把多个excel表都放在同一个文件夹里面,并在这个文件夹里面新建一个excel。

    其他2020-01-15
  • Copyright &#169; <script>var d=new Date();document.write(d.getFullYear());</script> FFan. All rights reserved.

    部分JS效果2020-01-15
  • 四边为虚线边框:border:1px dashed #000; 左边为虚线:border-left:1px dashed #000; 右边为虚线:border-right:1px dashed #000; 顶部边(上边)为虚线:border-top:1px dashed #000; 底部边(下边)为虚线:border-bottom:1px dashed #000;

    CSS2020-01-15