As a good practice I think it is a good idea to test if a popup was blocked and take action in case. You need to know that window.open has a return value, and that value may be null if the action failed. For example, in the following code:
function pop(url,w,h) {
n=window.open(url,'_blank','toolbar=0,location=0,directories=0,status=1,menubar=0,titlebar=0,scrollbars=1,resizable=1,width='+w+',height='+h);
if(n==null) {
return true;
}
return false;
}
if the popup is blocked, window.open will return null. So the function will return false.
As an example, imagine calling this function directly from any link
with target="_blank"
: if the popup is successfully opened, returning
false
will block the link action, else if the popup is blocked,
returning true
will let the default behavior (open new _blank
window) and go on.
<a href="http://whatever.com" target="_blank" onclick='return pop("http://whatever.com",300,200);' >
This way you will have a popup if it works, and a _blank window if
not.
If the popup does not open, you can:
- open a blank window like in the example and go on
- open a fake popup (an iframe inside the page)
- inform the user ("please allow popups for this site")
- open a blank window and then inform the user
etc..