Hey guys,
So I would like to be able to detect if my site is being loaded in an iframe and hide the header and the footer if it is. In JS this would be accomplished by doing something like:
if ( window.location !== window.parent.location ) {
// it’s in an iframe
header.style.display = “none”;
footer.style.display = “none”;
}
How do I adapt this with WixCode? I’ve tried substituting wixWindow but I get the error ‘location is undefined’.
I’ve tried searching through the forum and the WixCode documentation but haven’t had much luck. Any help is greatly appreciated!
Edit: it appears ‘location’ in Wix refers to the Google Maps API. Is there an alternative in Wix Code?
WixCode understands all of Javascript, except for anything that accesses the DOM. This keeps the user from inadvertently “breaking” something. I myself tried to hack things from the code, from an iFrame, and in my dreams, but WixCode wasn’t having any of it. Accessing document elements such as div, span, button, etc is off-limits. The way to access elements on the page is only through $w.
In other words, “you can’t do it”.
Thanks for the reply Yisrael, I understand why they would build it that way, but it can certainly get frustrating.
Maybe you can help me think of a work around to my problem. I’m trying to embed pages in a hybrid mobile app, have the website detect it’s being embedded and subsequently hide the header and the footer.
Could I send a postMessage from the parent to the wix, then use the onMessage on the Wix page to hide the header and footer?
Edit: it appears Wix can only receive messages from it’s child pages?
You can’t hide the header and footer on a Wix page. And Wix Code doesn’t allow access to the DOM. I myself tried to hack things from the code, from an iFrame, and in my dreams, but WixCode wasn’t having any of it.
@yisrael-wix damn. Back to the drawing board I guess. Thanks for the help Yisrael!
@danielanderson Glad to help - or at least try. Good luck