轉自:http://hi.baidu.com/zhuifengh2o/item/4cba119a95b69837336eebe0
| 123 |
<script> alert(screen.width + "*" + screen.height) </script> |
輸出當前螢幕的寬度和高度;
| 12345678910111213 |
<SCRIPT LANGUAGE="JavaScript"> var s = "網頁可見地區寬:" + document.body.clientWidth; s += "\r\n網頁可見地區高:" + document.body.clientHeight; s += "\r\n網頁本文全文寬:" + document.body.scrollWidth; s += "\r\n網頁本文全文高:" + document.body.scrollHeight; s += "\r\n網頁本文部分上:" + window.screenTop; s += "\r\n網頁本文部分左:" + window.screenLeft; s += "\r\n螢幕解析度的高:" + window.screen.height; s += "\r\n螢幕解析度的寬:" + window.screen.width; s += "\r\n螢幕可用工作區高度:" + window.screen.availHeight; s += "\r\n螢幕可用工作區寬度:" + window.screen.availWidth; alert(s); </SCRIPT> |
document.body.clientWidth ==> BODY對象寬度
document.body.clientHeight ==> BODY對象高度
document.documentElement.clientWidth ==> 可見地區寬度
document.documentElement.clientHeight ==> 可見地區高度
輸出網頁的各部分寬高值;
| 123 |
<script> window.open('Default.aspx', 'newwindow', 'height=500, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') </script> |
window.open的用法:
default.aspx:要開啟的頁面
newwindow:視窗名稱,也可以為_self,_blank等參數
height:視窗高度
width:視窗寬度
toolbar:是否顯示工具列(yes,no)
menubar:是否顯示功能表列(yes,no)
scrollbars:是否出現捲軸(yes,no)
resizable:是否可以改變視窗大小(yes,no)
location:是否顯示地址欄(yes,no)
status:是否顯示狀態列(yes,no)
top,left:視窗開啟時的座標;
| 12345678 |
<script> function centerWindow(url, w, h) { l = (screen.width - w) / 2 t = (screen.height - h) / 2 window.open(url, '', "height=" + w + ",width=" + h + ",top=" + t + ",left=" + l + ""); } </script> <input type="button" onclick="centerWindow('http://www.youth21.i.sohu.com','400','400')"/> |
開啟一個新的頁面置中顯示;開啟空白頁centerwindow(’about:blank’,800,500)
| 1234567891011121314 |
<SCRIPT LANGUAGE="JavaScript"> redirectPage(); function redirectPage() { /*var url640x480 = "http://www.baidu.com";**記得改相應的頁面*/ var url800x600 = "http://www.baidu.com"; var url1024x768 = "http://youth21.i.sohu.com"; /*if ((screen.width == 640) && (screen.height == 480)) window.location.href= url640x480;*/ if (screen.width <= 800) window.location.href = url800x600; else if ((screen.width >= 1024)) window.location.href = url1024x768; } </script> |
根據解析度大小或螢幕寬度開啟不同的頁面;
| 1234567891011121314151617 |
空間首頁 http://hi.baidu.com/zhuifengh2o 風雲人物 http://hi.baidu.com/zhuifengh2o/archive/tag/hourman 電腦檔 http://hi.baidu.com/zhuifengh2o/archive/tag/pc 文章 http://hi.baidu.com/zhuifengh2o/archive/tag/article 美圖 http://hi.baidu.com/zhuifengh2o/archive/tag/image 視頻 http://hi.baidu.com/zhuifengh2o/archive/tag/movie 遊戲 http://hi.baidu.com/zhuifengh2o/archive/tag/game 網站知識 http://hi.baidu.com/zhuifengh2o/archive/tag/web 網路工程 http://hi.baidu.com/zhuifengh2o/archive/tag/network%20engineer |