dede手机站链接一对一跳转设置

在做织梦的PC端手机端一对一链接适配跳转的时候经常需要用到的就是获取当前文章链接地址、获取当前栏目链接等。一个完整的跳转地址设置方法如下:

之前做法:

内容的跳转:

<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script>	
<script type="text/javascript">uaredirect("http://手机站网址{dede:field name='arcurl'/}");</script>

栏目列表页的跳转:

<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect("http://手机站网址{dede:type}[field:typelink /]{/dede:type}");</script> 

Tag页面跳转

<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script>	
<script type="text/javascript">uaredirect("http://m.landsj.cn{dede:tag row='1'}[field:link/]{/dede:tag}");</script> 

 

当然主页的跳转就只需要将上述任意一处的链接中的变量去掉就行了。

现在做法将:

http://siteapp.baidu.com/static/webappservice/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
            }
        }
    }
};

原因在于:公共资源有时候会因为网络原因,严重影响网页加载时间。

主要注意的一点是:如果栏目页链接不是默认链接,且直接在更目录的需要手动设置写死对应的跳转链接。否则会出现错误。

补充:跳转适配中还可以使用配置文件【.htaccess】形式,如

# 将 RewriteEngine 模式打开
RewriteEngine On
RewriteBase /
# Rewrite 规则 判断用户浏览器类型,如果是手机就跳转到手机网站
RewriteCond %{HTTP_USER_AGENT} "(baidu.Transcoder|mini|android|blackberry|googlebot-mobile|iemobile|Mobile|ipad|iphone|ipod|opera mobile|palmos|webos|ucweb|Windows Phone|Symbian|hpwOS)" [NC]
RewriteRule ^(.*)$ http://m.weguiding.com/?fromPC=http://www.weguiding.com [L,R=302]

如此情况就不需要用JS代码。

    PC 到 手机需要用到的代码

    列表
    <meta name="applicable-device" content="pc">
    <link rel="alternate" media="only screen and (max-width: 640px)" href="{dede:global.cfg_waphost/}{dede:type}[field:typelink /]{/dede:type}" >
    <script src="/js/wap.js" type="text/javascript"></script>
    <script type="text/javascript">uaredirect("{dede:global.cfg_waphost/}{dede:type}[field:typelink /]{/dede:type}");</script>
    
    栏目
    <meta name="applicable-device" content="pc">
    <link rel="alternate" media="only screen and (max-width: 640px)" href="{dede:global.cfg_waphost/}{dede:field name='arcurl'/}" >
    <script src="/js/wap.js" type="text/javascript"></script>
    <script type="text/javascript">uaredirect("{dede:global.cfg_waphost/}{dede:field name='arcurl'/}");</script>
    
    内容页
    <meta name="applicable-device" content="pc">
    <link rel="alternate" media="only screen and (max-width: 640px)" href="{dede:global.cfg_waphost/}{dede:field name='arcurl'/}" >
    <script src="/js/wap.js" type="text/javascript"></script>
    <script type="text/javascript">uaredirect("{dede:global.cfg_waphost/}{dede:field name='arcurl'/}");</script>
    
    
    
    移动端
    
    列表
    <meta name="applicable-device" content="mobile">
    <link rel="canonical" href="{dede:global.cfg_pchost/}{dede:type}[field:typelink /]{/dede:type}" >
    栏目
    <meta name="applicable-device" content="mobile">
    <link rel="canonical" href="{dede:global.cfg_pchost/}{dede:field name='arcurl'/}" >
    内容
    <meta name="applicable-device" content="mobile">
    <link rel="canonical" href="{dede:global.cfg_pchost/}{dede:field name='arcurl'/}" >
    
    
    
    自适应
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="applicable-device"content="pc,mobile">
    • 1
      点赞
    • 1
      收藏
      觉得还不错? 一键收藏
    • 0
      评论

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值