Work with Window
Attach HTML content
Use the attachHTML() method to attach HTML content to a window. The method takes a string with HTML as a parameter.
const dhxWindow = new dhx.Window({ title: "Window" });
const html = "<h1>Header</h1><p>paragraph</p>";
dhxWindow.attachHTML(html);
dhxWindow.show();
Related sample: Window. Attach HTML
Attach DHTMLX components
Use the attach() method to attach other DHTMLX components to a window:
dhxWindow.attach("richtext", { mode: "document" });
dhxWindow.show();
Related sample: Window. Attach widget
You can't attach Message, Popup, or Window to Window: these components can't have a parent container.
Repaint Window
If you change the configuration of a window, call the paint() method to repaint it on the page:
dhxWindow.paint();
Fullscreen mode
Call the setFullScreen() method to switch a window to full-screen mode:
dhxWindow.setFullScreen();
Related sample: Window. Fullscreen mode
To exit full-screen mode, call the unsetFullScreen() method:
dhxWindow.unsetFullScreen();
To check whether a window is in full-screen mode, use the isFullScreen() method:
dhxWindow.setFullScreen();
dhxWindow.isFullScreen(); // -> true
Show and hide Window
Use the show() and hide() methods to show and hide a window. The show() method takes two optional parameters:
If you call the method without parameters, it shows the window in the default position on the page.
// shows a window in the specified position
dhxWindow.show(34, 54);
// hides a window
dhxWindow.hide();
Related sample: Window. Showing / hiding Window
Set the active state
When you work with several windows, you may need to make one of them active and bring it to the front. To do this, call the setActive() method of that window.
The example below creates two windows. The second window overlaps the first one on initialization, and the setActive() call brings the first window back to the front.
const windowConfig = {
width: 300,
height: 300,
html: "<div style='padding: 20px'>Window content</div>"
};
const window1 = new dhx.Window({
...windowConfig,
title: "Window 1",
});
const window2 = new dhx.Window({
...windowConfig,
title: "Window 2",
});
// displaying both windows
window1.show();
window2.show(); // Window 2 is currently on top
// bringing Window 1 to the front without refreshing its content
window1.setActive();
Related sample: Window. Setting the active state
The setActive() method activates a window without re-rendering its content. The DOM state, such as form input values, scroll positions, or media playback, stays intact.
Set and get Window size
Use the setSize() method to change the size of a window. The method takes two parameters:
dhxWindow.setSize(250, 250);
To get the current size of a window, use the getSize() method. The method returns an object with the width and height of the window:
const size = dhxWindow.getSize(); // -> {width: 960, height: 469}
Related sample: Window. Set/get Window size
Set and get Window position
Use the setPosition() method to set the position of a window dynamically. The method takes two parameters:
dhxWindow.setPosition(20, 20);
dhxWindow.show();
To get the current position of a window, use the getPosition() method. The method returns an object with the left and top coordinates of the window:
const position = dhxWindow.getPosition(); // -> { left: 480, top: 234 }
Related sample: Window. Get/set Window position
Check Window visibility
The isVisible() method checks whether a window is visible. It returns true if the window is visible and false otherwise.
const visible = window.isVisible(); // -> true/false
Related sample: Window. Get Window visible status