Do you know you should not open popup windows and use a javascript modal instead?

Updated by Brook Jeynes [SSW] 2 years ago. See history

123
<introEmbed body={<> The popup blockers in several browsers prevent JavaScript from being used to open windows without user interaction (e.g. clicking a link). You should use an anchor tag instead. </>} />
<body onload="window.open('http://www.mydomain.com/document.html');return true;">

❌ Figure: Figure: Bad example - Using JavaScrip in OnLoad event

<a href="http://www.mydomain.com/document.html" target="_new">Document</a>

✅ Figure: Figure: Good example - Using HTML anchor tag. This will open in a new tab or window depending upon browser configuration

<a href="#" onclick="window.open('http://www.mydomain.com/document.html');return false;">Document</a>

✅ Figure: Figure: Good example - Using Javascript in an onclick event means you can force a popup window in preference to a new tab and also control the size and placement of the window

We have a program called SSW Code Auditor to check for this rule.

Acknowledgements

Adam Cogan
Related rules

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star