国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

詳解JavaScript編程中的window與window.screen對象

2019-11-25 17:03:14
字體:
來源:轉載
供稿:網友

Window 對象
所有瀏覽器都支持 window 對象。它表示瀏覽器窗口。
所有 JavaScript 全局對象、函數以及變量均自動成為 window 對象的成員。
全局變量是 window 對象的屬性。
全局函數是 window 對象的方法。
甚至 HTML DOM 的 document 也是 window 對象的屬性之一:

window.document.getElementById("header");

與此相同:

document.getElementById("header");

Window 尺寸
有三種方法能夠確定瀏覽器窗口的尺寸(瀏覽器的視口,不包括工具欄和滾動條)。
對于Internet Explorer、Chrome、Firefox、Opera 以及 Safari:

  • window.innerHeight - 瀏覽器窗口的內部高度
  • window.innerWidth - 瀏覽器窗口的內部寬度

對于 Internet Explorer 8、7、6、5:

  • document.documentElement.clientHeight
  • document.documentElement.clientWidth

或者

  • document.body.clientHeight
  • document.body.clientWidth

實用的 JavaScript 方案(涵蓋所有瀏覽器):

實例

var w=window.innerWidth|| document.documentElement.clientWidth|| document.body.clientWidth;var h=window.innerHeight|| document.documentElement.clientHeight|| document.body.clientHeight;

該例顯示瀏覽器窗口的高度和寬度:(不包括工具欄/滾動條)

Window Screen
window.screen對象在編寫時可以不使用 window 這個前綴。
一些屬性:

  • screen.availWidth - 可用的屏幕寬度
  • screen.availHeight - 可用的屏幕高度
  • Window Screen 可用寬度
  • screen.availWidth 屬性返回訪問者屏幕的寬度,以像素計,減去界面特性,比如窗口任務欄。

實例

返回您的屏幕的可用寬度:

<script>document.write("Available Width: " + screen.availWidth);</script>

以上代碼輸出為:

Available Width: 1440

Window Screen 可用高度
screen.availHeight 屬性返回訪問者屏幕的高度,以像素計,減去界面特性,比如窗口任務欄。
實例
返回您的屏幕的可用高度:

<script>document.write("Available Height: " + screen.availHeight);</script>

以上代碼將輸出:

Available Height: 860

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 启东市| 沙田区| 德保县| 东海县| 龙口市| 龙南县| 澄迈县| 柳河县| 额尔古纳市| 珲春市| 壤塘县| 定结县| 昌宁县| 繁昌县| 苍南县| 宝丰县| 饶河县| 广宗县| 芷江| 辉南县| 连州市| 宜宾县| 贵州省| 孝昌县| 东乡族自治县| 六安市| 巍山| 台江县| 凤翔县| 纳雍县| 萨迦县| 任丘市| 安阳市| 利川市| 错那县| 屏东市| 天镇县| 华阴市| 闸北区| 册亨县| 大丰市|