2010-07-03 38 views

回答

4

window.self屬性是一個參考回到window,而window.location是相同的對象document.location

因此,使表達式成爲真實的唯一可能性是重新定義selfdocument

+0

窗口是全局對象的一個​​屬性,它是全局對象的引用。 DOM充滿了神祕感...... :) – galambalazs 2010-07-04 11:55:05

1

我想這取決於範圍。據我所知,可以在對象中甚至在全局範圍內(重新)定義self,所以在這種情況下,self.location將指向無。就像這樣:

//[in global scope] 
var self = new SomeObject; 
alert(self.loction); //undefined 

//in a constructor 
function SomeObject(){ 
    var self = this; 
    alert(self.location); //undefined 
} 

底線似乎:不要一味依賴於self作爲別名可用性document

0

document.location是一個字符串,而不是一個對象, 它已被document.URL取代。

由服務器重定向的url不必更新window.location, ,但document.URL總是顯示當前文檔的路徑。

0

由於我不能發表評論,顯然self.location == document.location == window.location在一個框架中。只有top.location是不同的。 (在Firefox 3.6.6和Internet Explorer 8中測試)

相關問題