JavaScript學習筆記之內建對象,javascript學習筆記
JS Window
視窗對象:http://www.w3school.com.cn/js/js_window.asp
所有瀏覽器都支援window對象。它表示瀏覽器視窗。
所有 JavaScript 全域對象、函數以及變數均自動成為window對象的成員。
視窗對象的屬性和方法格式:
[window.]屬性
[window.]方法(參數)
甚至 HTML DOM 的 document 也是 window 對象的屬性之一:
window.document.getElementById("header");
與此相同:
document.getElementById("header");
JS Screen
螢幕對象:http://www.w3school.com.cn/js/js_window_screen.asp
螢幕對象主要描述螢幕的顯示及顏色屬性。
螢幕對象的屬性:
格式:screen.屬性
screen.availWidth - 可用的螢幕寬度
screen.availHeight - 可用的螢幕高度
以像素計,減去介面特性,比如視窗工作列。
JS Location
位置對象:http://www.w3school.com.cn/js/js_window_location.asp
位置對象用來代表特定視窗的URL資訊。
window.location 對象在編寫時可不使用 window 這個首碼。
一些例子:
location.hostname 返回 web 主機的網域名稱
location.pathname 返回當前頁面的路徑和檔案名稱
location.port 返回 web 主機的連接埠(80 或 443)
location.protocol 返回所使用的web協議(http:// 或 https://)
location.href 屬性返回當前頁面的 URL。
location.assign() 方法載入新的文檔。
JS History
曆史對象:http://www.w3school.com.cn/js/js_window_history.asp
曆史對象用以儲存用戶端最近訪問的網址清單。
為了保護使用者隱私,對 JavaScript 訪問該對象的方法做出了限制。
一些方法:
history.back() - 與在瀏覽器點擊後退按鈕相同
history.forward() - 與在瀏覽器中點擊按鈕向前相同
檔案對象
檔案對象: 代表當前HTML對象,是由<body>標籤組構成的,對每個HTML檔案會自動建立一個檔案對象。
格式:
document.屬性
document.方法(參數)
連結化物件
網頁中的連結均會被自動看作連結化物件,並依順序,分別表示為document.links[0],document.links[1]...
定義連結化物件的格式:
字串.link(屬性)
表單對象
檔案對象的子物件,Javascript的runtime engine自動為每一個表單建立一個表單對象。
格式:
document.forms[索引].屬性
document.forms[索引].方法(參數)
document.表單名稱.屬性
document.表單名稱.方法(參數)