top.location
and self.location
are Location objects. Objects in JavaScript can't be directly compared using ==
or ===
, which is why top.location != self.location
.
Since top.location.href
and self.location.href
are conventional strings, they can be compared as usual using ==
or, better, ===
.