return popup;
// Focus the new window popup.focus();
// Helpful features string const features = [ width=$width , height=$height , left=$left , top=$top , 'resizable=yes', 'scrollbars=yes', 'toolbar=yes', 'location=yes', 'menubar=yes', 'status=yes' ].join(','); window.open features
// Use it const win = window.open('/help', 'HelpWindow', getCenteredFeatures(900, 650)); return popup; // Focus the new window popup
function openSmartPopup(url, title, width = 800, height = 600) // Prevent double-popup if already open if (window.popupRef && !window.popupRef.closed) window.popupRef.focus(); return window.popupRef; // Center the window const left = (screen.width - width) / 2; const top = (screen.height - height) / 2; // Focus the new window popup.focus()
Here’s a helpful, practical feature using window.open() with useful features — a that opens a centered, resizable, focused child window with safe defaults and a fallback for popup blockers.