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';//改變框架內容