Is there a case where self.location! = Document.location?

Is there a case in JavaScript when self.location != document.location?

+3
source share
4 answers

The property window.selfis a reference to window, and window.locationis the same object as document.location.

Thus, the only way to return this expression is to override either self, or document.

+4
source

I suppose it depends on the scope. As far as I know, you can (re) define selfin an object or even in a global scope, so in this case self.locationit will not indicate anything. 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
}

: self document

+1

document.location - , not an object, and it has been replaced by document.URL.

The URL redirected by the server should not update window.location, but document.URL always shows the path to the current document.

0
source

Since I cannot post a comment, apparently self.location== document.location== window.locationin the frame. Only top.locationdifferent. (Tested in Firefox 3.6.6 and Internet Explorer 8)

0
source

Source: https://habr.com/ru/post/1752976/


All Articles