JS代码 ( 推荐 )
- 船说用户将此代码复制到 tpl_header.php 模板文件中(推荐)
- 或去掉前后的 <script> 放入 /www/static/模板文件夹/common.js 最前面
<script>if(navigator.userAgent.toLowerCase().match(/(ipod|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null){//判断是否为移动端if( window.location.host != 'm.xxx.com' ){window.location = 'http://m.xxx.com' + window.location.pathname;//带路径跳转}}</script><script> if(navigator.userAgent.toLowerCase().match(/(ipod|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null){ //判断是否为移动端 if( window.location.host != 'm.xxx.com' ){ window.location = 'http://m.xxx.com' + window.location.pathname; //带路径跳转 } } </script><script> if(navigator.userAgent.toLowerCase().match(/(ipod|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null){ //判断是否为移动端 if( window.location.host != 'm.xxx.com' ){ window.location = 'http://m.xxx.com' + window.location.pathname; //带路径跳转 } } </script>
PHP代码( 不建议 )
function ismobile(){if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {return true;} else {if (isset($_SERVER['HTTP_VIA']) && stripos($_SERVER['HTTP_VIA'], 'wap') !== false) {return true;} else {if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|phone|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|wap|windows ce|xda |xda_|xoom)/i', $_SERVER['HTTP_USER_AGENT'])) {return true;} else {if (isset($_SERVER['HTTP_ACCEPT']) && stripos($_SERVER['HTTP_ACCEPT'], 'text/html') === false && (stripos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false || stripos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.xhtml+xml') !== false)) {return true;} else {return false;}}}}}function ismobile(){ if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) { return true; } else { if (isset($_SERVER['HTTP_VIA']) && stripos($_SERVER['HTTP_VIA'], 'wap') !== false) { return true; } else { if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|phone|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|wap|windows ce|xda |xda_|xoom)/i', $_SERVER['HTTP_USER_AGENT'])) { return true; } else { if (isset($_SERVER['HTTP_ACCEPT']) && stripos($_SERVER['HTTP_ACCEPT'], 'text/html') === false && (stripos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false || stripos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.xhtml+xml') !== false)) { return true; } else { return false; } } } } }function ismobile(){ if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) { return true; } else { if (isset($_SERVER['HTTP_VIA']) && stripos($_SERVER['HTTP_VIA'], 'wap') !== false) { return true; } else { if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|phone|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|wap|windows ce|xda |xda_|xoom)/i', $_SERVER['HTTP_USER_AGENT'])) { return true; } else { if (isset($_SERVER['HTTP_ACCEPT']) && stripos($_SERVER['HTTP_ACCEPT'], 'text/html') === false && (stripos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false || stripos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.xhtml+xml') !== false)) { return true; } else { return false; } } } } }
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容