Window.open Features -
// 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`;
if (!popup) // Popup blocked alert('Popup was blocked. Please allow popups for this site or click the link manually.'); return null; window.open features
// Store reference window.popupRef = popup; // Usage openSmartPopup('https://example
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'
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;
const popup = window.open(url, title, features);
// 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(',');
