When visiting a page with iframe, how to determine whether it is cross-domain or not

I know the same origin policy, and I just want to ask how I can tell whether it is cross-domain or not. Parent.xx or top.xx, in a subdomain will report an error directly when crossing a domain, so how can it avoid reporting an error?

Mar.31,2021

it would be nice to judge whether the domain name in the src attribute of ifame is the same as the domain name of the page where iframe is located.

if you want to judge in iframe, it is recommended to pass in the domain name of the current page as a parameter when setting iframe src, so that you can determine whether it is of the same origin as the caller in iframe.

Menu