PC端代码:
实现手机访问,自动跳转网站手机版!
百度Site App的uaredirect.js实现手机访问,自动跳转网站手机版!
以下为代码,可放置在网站foot底部文件,或者haead顶部文件,建议将代码放在网站顶部,这样可以实现手机访问立即跳转!
<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script><script type="text/javascript">uaredirect("http://m.wangshifan.com");</script>
将代码网址部分改成你网站的手机网址就行了,当然可以是任意网址!这应该就是传说中的WAP自动跳转吧!
移动端代码:
<!--非移动端访问将跳转至PC页--> <script type="text/javascript"> (function(Switch){ var switch_mob = window.location.hash; if(switch_mob != "#mobile"){ if(!/iphone|ipod|ipad|ipad|Android|nokia|blackberry|webos|webos|webmate|bada|lg|ucweb|skyfire|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile/i.test(navigator.userAgent.toLowerCase())){ Switch.location.href='http://www.wangshifan.com/'; } } })(window); </script>
-------------------------------------------手机自动识别跳转---------------------------------------------------------
<script type="text/javascript"> var mobileUrl="你的手机网站首页", mobile = (/mmp|symbian|smartphone|midp|wap|phone|xoom|iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())); if (mobile) { window.location = mobileUrl; } </script>
网友留言: