js判断是否手机端,相对域名跳转到对应的m.手机站

访客4年前黑客工具1157
<script type="text/javascript">(function(Switch) {    var switch_pc = window.location.hash;    var curURL = document.location.href; //当前URL
    var isMobile = curURL.indexOf("http://m."); //判断当前URL是否是手机站
    var isPc = curURL.indexOf("http://www."); //判断当前URL是否包含"http://www."
    if (isMobile < 0) { //不是手机站
        if (isPc < 0) { //不包含"http://www."
        var thisURL = curURL.replace(/^http:\/\//, "http://m.");
    } else { // 包含"http://www."
        var thisURL = curURL.replace(/^http:\/\/www\./, "http://m.");
    }
  }  if (switch_pc != "#pc") {    if (/iphone|ipod|ipad|ipad|Android|nokia|blackberry|webos|webos|webmate|bada|lg|ucweb|skyfire|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile/i.test(navigator.userAgent.toLowerCase())) {
      Switch.location.href = thisURL;
    }
    document.write('<meta name="mobile-agent" content="format=html5;url=' + thisURL + '" />');
  }
})(window);</script>


标签: *** 实例

相关文章

JS打印机效果代码整理

纯js性 简单快速 功能少 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl...

aos.js超赞页面滚动元素动画特效jQuery动画库

简要教程 aos.js是一款效果超赞的页面滚动米素动画jQuery动画库插件。该动画库可以在页面滚动时提供28种不同的米素动画效果,以及多种easing效果。在页面往回滚动时,米素会恢复到原来的状态...

js获取当前位置

手机端获取城市名称 百度地图接口 引入百度api<script src="http://api.map.baidu.com/api?v=1.4" type="text/javascript"...

简单的返回顶部特效

首先引入jQuery js代码如下 $(function(){         //当滚动条的位置处于距顶部100像素以下时,跳转链接出现,否则消失         $(function () {  ...

js屏蔽F12和右键代码

//屏蔽F12和右键  function click(e) { if (document.all) { if (event.button==2||event.button==3) { alert("你...

[JS]文字逐字打出

好久不更新了 [JS]文字逐字打出 代码如下 <!DOCTYPE html> <html>     <head>         <meta char...