javascript: detect pop-up blocker

bert

OSNN One Post Wonder
Joined
14 Jul 2005
Messages
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.
 
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 profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,623
Latest member
AndersonLo
Back