"document" VS "wwLib.getFrontDocument()"

I’ve just stumbled upon this article, which states:

As you can see, we access the DOM through a document variable which is common among all browsers (chrome, firefox, arc, etc). But, in the case of WeWeb, while in the no-code editor, that won’t work.

Indeed, while working in WeWeb, your app is created inside an iframe (kind of a webpage inside the current webpage). To select it, you should replace document by wwLib.getFrontDocument().

So, for the first example, where we select an element by its id, it becomes:

var element = wwLib.getFrontDocument().getElementById("myElement");

I’m a bit surprised, since so far I’ve been using standard Javascript formulas, such as document.getElementById("myElement"); without problem.

Just wanted to check with y’all if I should go ahead and convert all my document.getElementById("myElement"); to wwLib.getFrontDocument().getElementById("myElement"); in order to avoid any potential problems I might not be aware of in the future, or if I can safely stick to the standard document.getElementById("myElement");?

WHen in the editor, weweb utilizes an iFrame and can get confused when referencing document and window. That’s why wwLib.getFrontWindow and wwLib.getFrontDocument are useful.

In published contexts, they just point to document and window objects, so there’s no impact.

3 Likes

Thank you @raydeck