window的主對象主要有以下幾個:javascript
document 對象;html
frames 對象;java
history 對象;函數
location 對象;post
navigator 對象;url
screen 對象;spa
全局變量和函數都是window的屬性。code
window的窗體函數:htm
open() 函數:打開(彈出)一個新的窗體;對象
close() 函數:關閉窗體;
opener 屬性:經過opener能夠實現跨窗體之間的通信,可是要保證是在同一域名下,並且一個窗體要包含另外一個窗體的opener。
window.open(url, name, features, replace);
open函數參數說明:
url -- 要載入窗體的URL;
name -- 新建窗體的名稱(也能夠是HTML target屬性的取值,目標);
features -- 表明窗體特性的字符串,字符串中每一個特性使用逗號分隔;
replace -- 一個布爾值,說明新載入的頁面是否替換當前載入的頁面,此參數一般不用指定。
對話框函數:
alert() 函數;
confirm() 函數:返回boolean值;
prompt(str1,str2) 函數:可輸入對話框(「此處str1不能編輯」、「str2能夠編輯」)。
定時器經常使用函數:
時間等待與間隔函數:
setTimeout(a,b) 函數,指定時間以後執行的方法。a爲要執行的方法,b爲時間間隔,單位毫秒。
clearTimeout(i) 函數,清除指定的setTimeout函數執行,例:var i=setTimeout(a,b)。
setInterval(a,b) 函數,每隔時間b循環執行a;
clearInterval(i) 函數,清除定時器,例:var iu=setInterval。
window.location對象
解析URL對象location
location對象的屬性有:href,protocal,host,hostname,port,pathname,search,hash
document.write(location.href + "<br/>"); // http://localhost:4889/javascriptTest.html document.write(location.protocol + "<br/>"); // http: document.write(location.host + "<br/>"); // localhost:4889 document.write(location.hostname + "<br/>"); // localhost document.write(location.port + "<br/>"); // 4889 document.write(location.pathname + "<br/>"); // /javascriptTest.html document.write(location.search + "換行<br/>"); //http://localhost:4889/javascriptTest.html?id=1&name=張三 若是路徑是這樣,則輸出 ?id=1&name=%E5%BC%A0%E4%B8%89 document.write(location.hash); //http: //localhost:4889/javascriptTest.html#kk=你好?id=1&name=張三 若是路徑是這樣,則輸出 #kk=你好?id=1&name=張三