织梦的m文件夹为手机版,里面有list.php,view.php等文件.
如果需要手机上浏览电脑版页面,自动跳转到对应的手机页面,需要通过js实现
一,把下面代码放在文件uaredirect.js中并上传,假如上传到script目录中
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
}
}
}
};
二,在首页模板index.htm中加入以下代码
<script src="/script/uaredirect.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect("/m","");</script>
1
2
3
三,在类似list.htm的模板中加入列表相关js引用
<script src="/script/uaredirect.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect("/m/list.php?tid={dede:field.id/}","");</script>
1
2
三,在类似article_article.htm模板中加入
<script src="/script/uaredirect.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect("/m/view.php?aid={dede:field.aid/}","");</script>
1
2
然后生成静态或缓存
网友评论