In Javascript, is there a case where self.location != document.location?
I suppose it depends on the scope. As far as I know it is possible to (re)define self
in an object or even in the global scope, so in that case self.location
would point to nothing. Like this:
//[in global scope]
var self = new SomeObject;
alert(self.loction); //undefined
//in a constructor
function SomeObject(){
var self = this;
alert(self.location); //undefined
}
Bottom line seems: do not blindly depend on the availability of self
as alias for document
The window.self
property is a reference back to window
, and window.location
is the same object as document.location
.
So, the only possibility to get that expression to be true, is to redefine either self
or document
.
document.location is a string, not an object, and it has been replaced by document.URL.
An url that is redirected by the server does not have to update the window.location, but the document.URL always shows the path to the current document.
Since I can't post a comment, apparently self.location
== document.location
== window.location
in a frame. Only top.location
is different. (Tested in Firefox 3.6.6 and Internet Explorer 8)