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

之前做法:

内容的跳转:

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

栏目列表页的跳转:

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

Tag页面跳转

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

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

现在做法将:

http://siteapp.baidu.com/static/webappservice/uaredirect.js

替换为:

functionuaredirect(f){
try{
if(document.getElementById("bdmark")!=null){
return
}
varb=false;
if(arguments[1]){
vare=window.location.host;
vara=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){
varc=window.location.hash;
if(!c.match("fromapp")){
if((navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i))){
location.replace(f)
}
}
}
}catch(d){}
}
functionisSubdomain(c,d){
this.getdomain=function(f){
vare=f.indexOf("://");
if(e>0){
varh=f.substr(e+3)
}else{
varh=f
}
varg=/^www./;
if(g.test(h)){
h=h.substr(4)
}
returnh
};
if(c==d){
return1
}else{
varc=this.getdomain(c);
varb=this.getdomain(d);
if(c==b){
return1
}else{
c=c.replace(".","\.");
vara=newRegExp("\."+c+"$");
if(b.match(a)){
return2
}else{
return0
}
}
}
};

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

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

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

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

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