1. 写在js里的电脑手机端跳转 只需加载该js即可
// JavaScript Document
function urlredirect() {
var sUserAgent = navigator.userAgent.toLowerCase();
if ((sUserAgent.match(/(ipod|iphone os|midp|ucweb|android|windows ce|windows mobile)/i))) {
// 只适用盘古建站,PC跳转移动端
//var thisUrl = window.location.href;
var host = window.location.host;
//var host2=document.domain;
//window.location.href = thisUrl.substr(0,thisUrl.lastIndexOf('/')+1)+'wap/';
//alert(window.location.host);
window.location.href="http://"+host+"/index.php?m=Cnm";
}
}
urlredirect();
或者进行域名替换
<script>
window.onload=jstiao(); //自动加载
function jstiao(){
var widths = window.screen.availWidth;
if(widths > 1000){ //屏幕尺寸宽度小于1000,则执行域名替换,跳转
var domain = window.location.host; //获取当前域名
var url = document.location.toString(); //获取当前url
var result = url.replace(domain, "W3School");
window.location.href = result;
}
}
</script>