dede手机站链接一对一跳转设置
来源:互联网 发布:淘宝客新手教程 编辑:程序博客网 时间:2024/05/03 23:08
在做织梦的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 OnRewriteBase /# 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 0
- dede手机站链接一对一跳转设置
- dede判断手机访问电脑端网站跳转代码
- dede v57跳转网址直接链接而非直接中转的PHP文件
- 从app跳转到手机设置(代码)
- iOS 跳转到手机设置各种页面
- 访问同一域名,手机端跳转不同链接
- dede文章内容模型的跳转
- dede 跳转属性直接显示跳转网址
- 链接跳转
- dede安全设置【新】
- dede 安全性设置
- dede网站安全设置
- dede安全设置
- 手机跳转
- dede 获取文章链接地址
- Android TextView设置高亮,颜色,点击跳转链接
- dede实现手机wap浏览
- 关于获取手机网络以及如何跳转到设置界面
- 程序猿表情包合集,让你斗图再也不会输
- 十大ACE/ACED专家齐聚一堂,一场不容错过的数据技术盛会
- centos7安装JDK1.7
- VHDL常见的语法结构,粘贴此处方便查询
- C# winform DataGridView 常用属性(全)
- dede手机站链接一对一跳转设置
- CSS的单位及css3的calc()及line-height百分比
- 网上说的白帽子黑帽子都是什么?
- SpringBoot入门系列:eclipse如何构建一个最简单的springBoot项目。
- 科普:什么是IPS
- nginx同一iP多域名配置方法
- 百度地图UnsatisfiedLinkError问题
- jQuery实现初始化时滚动条在最底部
- Web前端——1.HTML标签