3 回答

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
window對(duì)象和document對(duì)象的區(qū)別
一般來(lái)講,一個(gè)window里就是一個(gè)document,但是,iframe里面也可以裝個(gè)document,在iframe里面就有區(qū)別了
alert(document.location === window.location); // true
不要混淆Window對(duì)象的location屬性和Document對(duì)象的location屬性。前者引用一個(gè)Location對(duì)象,而后者只是一個(gè)只
讀字符串,并不具有Location對(duì)象的任何特性。document.location與document.URL是同義的,后者在
JavaScript1.1中是該屬性的首選名稱(因?yàn)檫@樣避免了潛在的混淆)。在大多數(shù)情況下,document.location和
location.href是相同的。但是,當(dāng)存在服務(wù)器重定向時(shí),document.location包含的是已經(jīng)裝載的URL,而
location.href包含的則是原始請(qǐng)求的文檔的URL。
document.location和window.location有什么區(qū)別就是
document你可以理解為文檔,就是你的網(wǎng)頁(yè)
window理解為窗口,就是你的ie瀏覽器包含的
無(wú)框架:簡(jiǎn)單的說(shuō),沒有框架的情況下,是等同的
有框架:在有框架的情況下,最外層是相同的,在iframe里面的document.location和window.location不同的。
iframe里面的document.location 你看不ie地址變化,只改變iframe部分,
此時(shí)的window.location和top.location效果一致
document.location="url";(只讀)
document.location.reload("url";);
window.location="url";
location="url";
document.href="url"
document.location.href="url"
document.location.replace="url"
document.action="url"; document.submit();
document.location.href和document.location.replace都可以實(shí)現(xiàn)從A頁(yè)面切換到B頁(yè)面,但他們的區(qū)別是:
用document.location.href切換后,可以退回到原頁(yè)面。而用document.location.replace切換后,不可以通過(guò)“后退”退回到原頁(yè)面。
關(guān)于document.location.href或其他可回退的切換方式
document.location 相當(dāng)于 document.URL 聲明了裝載文檔的URL,
除非發(fā)生了服務(wù)器重定向, 否則該屬性的值與Window.location.href的值是一樣的.
history.go(-1);//返回上一頁(yè)
document.IFRAME名稱.location.href='url';//改變框架內(nèi)容

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊
javascript中的Window 對(duì)象表示瀏覽器中打開的窗口。
如果文檔包含框架(frame 或 iframe 標(biāo)簽),瀏覽器會(huì)為 HTML 文檔創(chuàng)建一個(gè) window 對(duì)象,并為每個(gè)框架創(chuàng)建一個(gè)額外的 window 對(duì)象。
注釋:沒有應(yīng)用于 window 對(duì)象的公開標(biāo)準(zhǔn),不過(guò)所有瀏覽器都支持該對(duì)象。
實(shí)際的window就是指一個(gè)窗口,比如windows的視窗操作都是一個(gè)window。

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊
1 2 3 4 5 | typeof Window; //function typeof window; //object
window.constructor===Window; //true window instanceof Window; //true |
說(shuō)明window是Window的實(shí)例,Window是window的構(gòu)建函數(shù)
添加回答
舉報(bào)