pc端:
var w = window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
var h = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
移動端:
網頁可見區域寬:document.body.clientWidth 網頁可見區域高:document.body.clientHeight 網頁可見區域寬:document.body.offsetWidth (包括邊線的寬) 網頁可見區域高:document.body.offsetHeight (包括邊線的寬) 網頁正文全文寬:document.body.scrollWidth 網頁正文全文高:document.body.scrollHeight 網頁被卷去的高:document.body.scrollTop 網頁被卷去的左:document.body.scrollLeft 網頁正文部分上:window.screenTop 網頁正文部分左:window.screenLeft 屏幕分辨率的高:window.screen.height 屏幕分辨率的寬:window.screen.width 屏幕可用工作區高度:window.screen.availHeight 屏幕可用工作區寬度:window.screen.availWidth
例:
<script type="text/javascript">
var w = window.innerWidth
|| document.documentElement.clientWidth //獲取pc的寬,一般在pc上調試的時候用
|| document.body.clientWidth;
var h = window.innerHeight
|| document.documentElement.clientHeight //獲取pc的高
|| document.body.clientHeight;
var w1 = window.screen.width //獲取手機屏幕的寬 ,在實際上線的時候使用
window.onload = function(){
if(w < 415){
window.location.assign('tf/index.html');
}else{
window.location.assign('sh/index.html');
}
if(w1 < 415){
window.location.assign('tf/index.html');
}else{
window.location.assign('sh/index.html');
}
}
</script>