javascript -window與document 待整理

來源:互聯網
上載者:User

 

window對象和document對象的區別
一般來講,一個window裡就是一個document,但是,iframe裡面也可以裝個document,在iframe裡面就有區別了

alert(document.location === window.location);  // true

 

 

不要混淆Window對象的location屬性和Document對象的location屬性。前者引用一個Location對象,而後者只是一個只
讀字串,並不具有Location對象的任何特性。document.location與document.URL是同義的,後者在
JavaScript1.1中是該屬性的首選名稱(因為這樣避免了潛在的混淆)。在大多數情況下,document.location和
location.href是相同的。但是,當存在伺服器重新導向時,document.location包含的是已經裝載的URL,而
location.href包含的則是原始請求的文檔的URL。

 

document.location和window.location有什麼區別就是
document你可以理解為文檔,就是你的網頁
window理解為視窗,就是你的ie瀏覽器包含的
無架構:簡單的說,沒有架構的情況下,是等同的
有架構:在有架構的情況下,最外層是相同的,在iframe裡面的document.location和window.location不同的。
iframe裡面的document.location 你看不ie地址變化,只改變iframe部分,
此時的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都可以實現從A頁面切換到B頁面,但他們的區別是:
用document.location.href切換後,可以退回到原頁面。而用document.location.replace切換後,不可以通過“後退”退回到原頁面。
關於document.location.href或其他可回退的切換方式
document.location 相當於 document.URL 聲明了裝載文檔的URL,
除非發生了伺服器重新導向, 否則該屬性的值與Window.location.href的值是一樣的.
history.go(-1);//返回上一頁
document.IFRAME名稱.location.href='url';//改變架構內容 
       

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.