Secret ingredients to quality software


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

Last updated by Tiago Araujo on 17 Nov 2016 04:18 pm (over 4 years 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="'');return true;">

Figure: Bad Example - using JavaScrip in OnLoad event

<a href="" 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="'');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.

Adam CoganAdam Cogan

We open source. This page is on GitHub