【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
<script type="text/javascript">
var siteurl = 'https://m.yourdomain.com';
// 跳桌面版
if (!(navigator.userAgent.match(/(iPhone|iPod|Android|Windows Phone)/i))) {
var url=window.location.href;
// url=url.replace('http://m.','http://www.');
url=url.replace('https://m.','https://www.');
location.replace(url);
}
</script>
上面代码是在手机模板head内加入
<script type="text/javascript">
var new_url = window.location.href;
if(new_url.indexOf('http://yourdomain') >= 0 || new_url.indexOf('https://yourdomain') >= 0) {
new_url = new_url.replace('http://yourdomain', 'http://www.yourdomain');
new_url = new_url.replace('https://yourdomain', 'http://www.yourdomain');
window.location.replace(new_url);
}
var siteurl = 'http://www.iyourdomain.net/';
</script>
<script type="text/javascript">
<!--跳m站-->
function getCookie(nm) {
var arr, reg = new RegExp("(^| )" + nm + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg)) {
return unescape(arr[2]);
} else {
return null;
}
}
if ((navigator.userAgent.match(/(iPhone|iPod|Android|Windows Phone)/i))) {
if(getCookie('mfjian') == null) {
var url = window.location.href;
url = url.replace('http://yourdomain', 'http://m.yourdomain');
url = url.replace('https://yourdomain', 'https://m.yourdomain');
url = url.replace('http://www.', 'http://m.');
url = url.replace('https://www.', 'https://m.');
location.replace(url);
}
}/*else{
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'http') {
var url=window.location.href;
url=url.replace('http://','https://');
location.replace(url);
}
}*/
</script>
在电脑模板head中加入
虽然有很多cms在后台PHP端已经做了客户访问端的平台属性判断,但是有很多时候 ,页面被缓存成静态,是不能跳转的,要加js识别代码。
故而,以上代码变得尤其重要。
来源:oschina
链接:https://my.oschina.net/u/218676/blog/3141991