核心提示:这是我用在dede织梦程序上的代码,所以只要是php写的应该都可以用?php////这段放手机站里header(Cache-Control: no-cache); header(Pragma: no-...
这是我用在dede织梦程序上的代码,所以只要是php写的应该都可以用
<?php ////这段放手机站里 header("Cache-Control: no-cache"); header("Pragma: no-cache"); $ua = strtolower($_SERVER['HTTP_USER_AGENT']); $uachar = "/(symbianos|android|iphone|ucweb|blackberry)/i"; if($ua != '' && !preg_match($uachar, $ua)){ echo 'window.location.href="https://www.domain.com";'; exit(); } ?>
<?php //这段放在电脑网站里 header("Cache-Control: no-cache"); header("Pragma: no-cache"); $ua = strtolower($_SERVER['HTTP_USER_AGENT']); $uachar = "/(symbianos|android|iphone|ucweb|blackberry)/i"; if($ua != '' && preg_match($uachar, $ua)){ echo 'window.location.href="https://https://m.domain.com/";'; exit(); } ?>
JS的写法
<script> var browser_class = navigator.userAgent; var browser_class_name1 = browser_class.match("Mobile"); var browser_class_name2 = browser_class.match("mobile"); var location_url = window.location.href; if (browser_class_name1 != null || browser_class_name2 != null){ if (location_url.match("wap") == null){ window.location.href="https://m.domain.com/"; } } else { if (location_url.match("3g") != null || location_url.match("wap") != null){ window.location.href="https://m.domain.com/"; } } </script>