1

I want to know how "location"(window.location) object is compared in javascript i.e. which values are taken into consideration while comparing two "location" objects.

Suppose i have top.location = "http://www.abc.com" and self.location = "http://www.abc.com". If i compare them as (top.location == self.location), it gives false. Whereas, if i compare them as (top.location.href == self.location.href), it will gives true.

Can anyone explain why this happens?

Thanks in advance.

1

1 Answer 1

3

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, ===.

Sign up to request clarification or add additional context in comments.

15 Comments

+1 I Objects can't be compared in JS. Thanks for letting us to know.
Yeah. So, is it that objects in javascript cannot be compared? Since, frame busting code uses top.location!=self.location and it works correctly.
I doubt it, they must be doing something else, although top.location!=self.location always equals true meaning the frame will always "bust"
Isn't there any method to achieve top.location==self.location?
Objects CAN be compared using == (property by property) or === (by reference).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.