Window.open Features [hot] -
if (!popup) // Popup blocked alert('Popup was blocked. Please allow popups for this site or click the link manually.'); return null;
This approach makes window.open() actually rather than annoying — respectful of user expectations, robust against blockers, and easy to reuse.
// Usage openSmartPopup('https://example.com', 'HelpfulWindow', 900, 700); | Feature | Benefit | |---------|---------| | Centered positioning | User-friendly, doesn't open off-screen | | Ref tracking | Reuses existing window instead of duplicate popups | | Focus handling | Brings existing popup to front if already open | | Fallback alert | Informs user if popup blocker interferes | | Sensible defaults | Includes toolbars, scrollbars, location bar for usability | | Auto cleanup | Removes reference when popup closes | Minimal version (if you just need the feature string): function getCenteredFeatures(w = 800, h = 600) const left = (screen.width - w) / 2; const top = (screen.height - h) / 2; return `width=$w,height=$h,left=$left,top=$top,resizable=yes,scrollbars=yes,toolbar=yes,location=yes`; window.open features
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;
// 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(','); robust against blockers
, 500);
// Optional: Auto-clean reference when closed const checkClosed = setInterval(() => if (popup.closed) clearInterval(checkClosed); if (window.popupRef === popup) window.popupRef = null; width = 800
// Use it const win = window.open('/help', 'HelpWindow', getCenteredFeatures(900, 650));





