0
votes

I have a Sitecore site where I need to implement an iframe communication solution that requires me to set document.domain = "mydomain.com" in JS in both the parent page (sitecore) and the child page (externally hosted on subdomain).

If I place document.domain = "mydomain.com" in the JS anywhere in my site, Page Editor and Preview in Sitecore both start throwing JS errors like confetti and most functionally it broken. When I remove it, everything goes back to normal. Very strange.

Any thoughts as to why this is happening and how we can work around it? Thanks.

1

1 Answers

0
votes

According to https://developer.mozilla.org/en-US/docs/Web/API/document.domain you can only set document.domain to a "superdomain" of the current site, so any cross-domain shenanigans wouldn't work. I don't see what the domains are you're working with, so without knowing that, I can only guess here.

In the event you did want to do cross-domain communication, you might give window.postMessage a shot https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage.