幫助

在手機(jī)端下,訪問PC端自動(dòng)跳轉(zhuǎn)手機(jī)網(wǎng)站的代碼

2021-10-13 17:53 易優(yōu)技巧

首先要區(qū)分網(wǎng)站是自適應(yīng)還是分離式模板,比如:自適應(yīng)=PC端和手機(jī)端共用模板,分離式=PC端和手機(jī)端分開模板

以下代碼只需在PC端模板里添加,移動(dòng)端模板不需要添加。

如果是分離式模板,請(qǐng)?jiān)?a href="http://22321a.com/moban/" target="_blank" >網(wǎng)站模板里的</head>之前加上以下代碼:

<meta http-equiv="mobile-agent" content="format=xhtml;url={$eyou.field.pageurl_m}">
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/applewebkit.*mobile/i.test(navigator.userAgent.toLowerCase()) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.userAgent.toLowerCase()))){try{if(/android|windows phone|webos|iphone|ipod|blackberry/i.test(navigator.userAgent.toLowerCase())){window.location.href="{$eyou.field.pageurl_m}";}else if(/ipad/i.test(navigator.userAgent.toLowerCase())){}else{}}catch(e){}}}</script>

如果是響應(yīng)式自適應(yīng)模板,而且后臺(tái)開啟并配置了手機(jī)端域名,請(qǐng)?jiān)诰W(wǎng)站模板里的</head>之前加上以下代碼:
<meta http-equiv="mobile-agent" content="format=xhtml;url={$eyou.field.pageurl_m}">
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/applewebkit.*mobile/i.test(navigator.userAgent.toLowerCase()) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.userAgent.toLowerCase()))){try{if(/android|windows phone|webos|iphone|ipod|blackberry/i.test(navigator.userAgent.toLowerCase())){if(window.location.toString().indexOf('{$eyou.field.mobile_domain}') == -1){window.location.href="{$eyou.field.pageurl_m}";}}else if(/ipad/i.test(navigator.userAgent.toLowerCase())){}else{}}catch(e){}}}</script>



標(biāo)簽: 手機(jī)端
QQ在線咨詢