• javascript 检测手机设备 百度siteapp下的一款跳转的产品,使用起来很方便。你可以用这款JS跳转到手机版,也可以跳转到任何你想跳转的位置。


    首先在你的head中嵌入这段代码
    
    <script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script>
    
    <script type="text/javascript">uaredirect("http://m.caijiayou.com","http://www.caijiayou.com");</script>
    
    第二行的样式参考这个就行了。将里面的域名改成你自己的。
    这里我们看得出,这里是引用了百度siteapp的uaredirect.js
    
    所以你也可以将该js文件下载到你的网站本地。
    
    下载地址:http://siteapp.baidu.com/static/webappservice/uaredirect.js
    
    我们将uaredirect.js格式化一下。
    
    uaredirect.js格式化后
     
     
    function uaredirect(f){
    try{
    if(document.getElementById("bdmark")!=null){
    return
    }
    var b=false;
    if(arguments[1]){
    var e=window.location.host;
    var a=window.location.href;
    if(isSubdomain(arguments[1],e)==1){
    f=f+"/#m/"+a;b=true
    }else{
    if(isSubdomain(arguments[1],e)==2){
    f=f+"/#m/"+a;b=true
    }else{
    f=a;b=false
    }
    }
    }else{
    b=true
    }if(b){
    var c=window.location.hash;
    if(!c.match("fromapp")){
    if((navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i))){
    location.replace(f)}
    }
    }
    }catch(d){
    
    }
    }
    function isSubdomain(c,d){
    this.getdomain=function(f){
    var e=f.indexOf("://");
    if(e>0){
    var h=f.substr(e+3)
    }else{
    var h=f
    }
    var g=/^www./;
    if(g.test(h)){
    h=h.substr(4)
    }
    return h
    };
    if(c==d){
    return 1
    }else{
    var c=this.getdomain(c);
    var b=this.getdomain(d);
    if(c==b){
    return 1
    }else{
    c=c.replace(".","\.");
    var a=new RegExp("\."+c+"$");
    if(b.match(a)){
    return 2
    }else{
    return 0
    }
    }
    }
    };
    
     
  • 相关阅读:
    回调函数(C语言)
    main函数的参数(一)
    术语,概念
    [LeetCode] Invert Binary Tree
    关于overload和override
    第一个只出现一次的字符
    Manacher算法----最长回文子串
    C++对象模型
    回文判断
    字符串转换成整数
  • 原文地址:https://www.cnblogs.com/benpaodegegen/p/8875935.html
Copyright © 2020-2023  润新知