最近有需求要实现用一个网址,在手机和电脑上实现不一样的效果。这种需求最好是使用响应式来实现,但我只有一个页面有这种需求,写响应式工作量太大,直接写2个页面做个移动端跳转。
只有当手机打开时才需要跳转到指定页面,电脑打开时不用跳转。这样同一个链接就在电脑端和手机端实现不一样的展示效果。
试了试下面2个方法:
<meta http-equiv="mobile-agent" content="format=xhtml;url=http://www.XX.com/1.html">
<script type="text/javascript">uaredirect("http://www.XX.com/1.html");</script>
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="http://www.XX.com/1.html";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
保存记录!