Can I call wixWindow.ScrollTo(0,0) from an iframe?

I put this in the code area of the Wix page:

import wixWindow from 'wix-window';

then tried making this call from a non-Wix page inside an iframe:

window.parent.wixWindow.ScrollTo(0,0)

Got this error: “Uncaught DOMException: Blocked a frame with origin “https://mydomain.com” from accessing a cross-origin frame.”

So, would I be able to do it if it were a Wix page inside the iframe?

The [short] answer: no

The explanation…
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.

One small exception is the $w.HtmlComponent (which is based on an iFrame). This element was designed to contain vanilla HTML and it works just fine. You just can’t try to trick it by using parent, window, top, etc. Same goes with the Javascript evaluate() function. It is sandboxed and does not allow access to the DOM.

So are you saying I would need to place all my javascript in the Code box (no iframe) and then just use

$w("#myElement").scrollTo()

What about CSS? Can we reference external CSS files?

Nope, your cannot reference css files.

Let us know what your are trying to do, we can probably do the same, if using a different way