0

I have a.example.com and b.example.com;

When I put b.example.com/foo as iframe in a.example.com:

<iframe src='b.example.com/foo'></iframe>`

the window.location.href value accessible from b.example.com is ... a.example.com/foo (??)...

The problem is - I use an external library in b.example.com/foo that checks for window.location.href and it gets incorrect information.

For this scenario it appears to me that I should iframe /foo content on a completely different domain like: anotherexample.com/foo, where the window.location.href would actually point to anotherexample.com/foo.

How can I force window object in iframe to actually use its subdomain instead of parent domain with added parameter?

sideshowbarker
89.2k30 gold badges219 silver badges216 bronze badges
asked Sep 24, 2021 at 16:13

1 Answer 1

1

Are you sure you are using your script in the right subdomain? it seems your external library is accessing parent window using window.parent.location, here is a code to check if a page is loaded directly or within another page:

var is_loaded_directly = (window.location == window.parent.location);

Since this code works, something is wrong on your setup or library.

Note: maybe you can solve your issue by checking document.location instead of window.location.

answered Sep 24, 2021 at 16:42
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.