當我們用手機訪問網站時,會自動跳轉到手機模板,這需要在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模板添加上面代碼后,手機訪問網站時,就會自動跳轉到手機網站模板了。 (責任編輯:jesse)學友請微信搜索好學網,或加公眾號 haoxueecom 獲取更多學習資訊! |