好学网移动版

好学网首页 > IT教育 > dedecms >

手机访问网站跳转代码汇总

       当我们用手机访问网站时,会自动跳转到手机模板,这需要在pc模板中添加跳转的js代码。在<head></head>添加代码。

* 首页模板中添加如下代码:

<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/index.php">

<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="{dede:global.cfg_mobileurl/}/index.php";}else if

(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

* 列表页模板添加如下代码:

<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/list.php?tid={dede:field.id/}">

<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="{dede:global.cfg_mobileurl/}/list.php?tid=

{dede:field.id/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

*内容页模板添加如下代码

<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/view.php?aid={dede:field.id/}">

<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="{dede:global.cfg_mobileurl/}/view.php?aid=

{dede:field.id/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

其中上面的js是电脑网站跳转到手机网站的代码,而<meta http-equiv="mobile-agent" ....>是用来告诉百度,手机网站的地址,主要用于seo。

pc模板添加上面代码后,手机访问网站时,就会自动跳转到手机网站模板了。

63.2K
    推荐阅读
    网站首页 网站地图 返回顶部
    好学网移动版(2001-2035)好学网电脑版