let windowUrl = "";
let windowName = "my-window";
let size = "width=600,height=400";
let htmlContent = "<h1>Hello, World!</h1>";
let existingWindow = window.open(windowUrl, windowName, size);
if(existingWindow) {
existingWindow.focus();
} else {
let newWindow = window.open(windowUrl, windowName, size);
newWindow.document.write(htmlContent);
newWindow.document.close();
}
This code snippet is connected to an onclick event. It checks if a window already exists and either refocuses on it or creates a new window with specified content.