• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

javascript: detect pop-up blocker

bert

OSNN One Post Wonder
#1
Hello,
I have a web site I am developing. The web page has a photography gallery portfolio on it with thumbnails. When the thumbnail are clicked on, they open in a new window. I would like to add to the javascript a detection and alert that notifies the user that the window did not open due to a popup blocker. Could somebody please help me with this, I can't figure out how to do it on my own.
Here is the original javascript for the window opener script:
<script language="JavaScript" type="text/JavaScript">
<!--
function viewPic(img)
{
picfile = new Image();
picfile.src =(img);
fileCheck(img);
}
function fileCheck(img)
{
if( (picfile.width!=0) && (picfile.height!=0) )
{
makeWindow(img);
}
else
{
funzione="fileCheck('"+img+"')";
intervallo=setTimeout(funzione,10);
}
}
function makeWindow(img)
{
ht = picfile.height;
wd = picfile.width;
var args= "height=" + ht + ",innerHeight=" + ht;
args += ",width=" + wd + ",innerWidth=" + wd;
if (window.screen)
{
var avht = screen.availHeight;
var avwd = screen.availWidth;
var xcen = (avwd - wd) / 2;
var ycen = (avht - ht) / 2;
args += ",left=" + xcen + ",screenX=" + xcen;
args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=no";
}
popwin=window.open("","_blank",args)
popwin.document.open()
popwin.document.write('<html><head><title>'+img+'</title></head><body bgcolor=black scroll=no topmargin=0 leftmargin=0 rightmargin=0 bottomargin=0 marginheight=0 marginwidth=0><div style="position: absolute; top:0px;left:0px"><img src="'+img+'" width="'+wd+'" height="'+ht+'" border="0"></div></body></html>')
popwin.document.close()

}
//-->
</script>
Now, I tried to modify that script, here is what I added to it:
-------
popwin=window.open("","_blank",args)
popwin.document.open()
if (popwin==null || typeof(popwin)=="undefined")
{
alert("window failed to open");
}
else
{
popwin.document.write('<html><head><title>'+img+'</title></head><body bgcolor=black scroll=no topmargin=0 leftmargin=0 rightmargin=0 bottomargin=0 marginheight=0 marginwidth=0><div style="position: absolute; top:0px;left:0px"><img src="'+img+'" width="'+wd+'" height="'+ht+'" border="0"></div></body></html>')
popwin.document.close()
}
}
--------
If somebody would be able to help me, it would be greatly appreciated. Thank you so much.
 

Khayman

I'm sorry Hal...
Political User
#2
Code:
if(!popwin) blah
should work
however, most people here (inc me) will tell you not to use popups, everyone hates them and may cause people to leave your site
 

Members online

No members online now.

Latest posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,013
Latest member
Pdawgintown