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

Last updated by Brook Jeynes [SSW] 8 months ago.See history

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: Bad example - Using JavaScrip in OnLoad event

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

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: 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.

We open source. Powered by GitHub