JSideris / DOThtml

A human-friendly way to build highly-dynamic web pages in pure JavaScript.
2 stars 4 forks source link

Support for other windows. #154

Open JSideris opened 10 months ago

JSideris commented 10 months ago

Users of the framework should be able to target other windows and write directly to them.

Something like this would be nice

let myWindow = window.open("", "My Popup", "width=500;height=500;");

dot(myWindow.document.body).div("Hello, World!");

The challenge here is that the function for creating elements lies within window.document, and it's a different object for every window. Elements from one window can't be transferred to another.

One option is to set the window based on the target element. We can get the window from the target element using this:

element.ownerDocument.defaultView || element.ownerDocument.parentWindow;

Another problem is components with dynamic elements that phase in and out of existence. Note that components don't use targeters. They just return dot syntax. One option here is to assign a window to the component before the builder is called. Then any new content generated by that component will use it's window. A component could potentially be used in multiple windows. Please test this before marking this as compete.

JSideris commented 9 months ago

Solution is you can pass a window object into the target, or as shown above, just choose a target node that's already on the target window. Scheduled to package with v6.