I have the code for a strategic popup, and it works great. The problem is I want to incorporate cookies into the popup script, so that returning users don't get annoyed by seeing the popup every single time they visit the site. I've tried on my own to incorporate the "cookie function" from other popup windows into my own popup code, but my programming skills just aren't good enough yet to successfully pull that off. Below is the original code for just the strategic popup without any cookie options (there are also two other pieces to the code in the body, but those just affect what's in the actual popup itself, so i'm sure this is where the cookie info would need to go): <script language="JavaScript" type="text/javascript"> <!-- var allowpop=1; function popWin(){ var ppl="popLayer";var objppl=findObj(ppl); if (objppl==null){return;}// if the layer does not exist, do nothing. var args=arguments,movetoX=parseInt(args[0]),movetoY=parseInt(args[1]),movespeed=parseInt(args[2]); var cycle=10,pxl=""; if(!document.layers){objppl=objppl.style;} if(objppl.tmofn!=null){clearTimeout(objppl.tmofn);} var pplcoordX=parseInt(objppl.left),pplcoordY=parseInt(objppl.top); var xX=movetoX,yY=movetoY;if((pplcoordX!=movetoX)||(pplcoordY!=movetoY)){ var moveX=((movetoX-pplcoordX)/movespeed),moveY=((movetoY-pplcoordY)/movespeed); moveX=(moveX>0)?Math.ceil(moveX):Math.floor(moveX);movetoX=pplcoordX+moveX; moveY=(moveY>0)?Math.ceil(moveY):Math.floor(moveY);movetoY=pplcoordY+moveY; if((parseInt(navigator.appVersion)>4||navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {pxl="px";} if (moveX!=0){eval("objppl.left='" + movetoX + pxl + "'");} if (moveY != 0) {eval("objppl.top = '" + movetoY + pxl + "'");} var sFunction = "popWin(" + xX + "," + yY + "," + movespeed+ ")"; objppl.tmofn = setTimeout(sFunction,cycle); } } function findObj(theObj, theDoc){ var p, i, foundObj; if(!theDoc) theDoc = document; if((p = theObj.indexOf("?")) > 0 && parent.frames.length) {theDoc = parent.frames[theObj.substring(p+1)].document; theObj = theObj.substring(0,p);} if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj]; for (i=0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj]; for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj,theDoc.layers[i].document); if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj); return foundObj; } function hideLayer(layername){ layer=findObj(layername); if(layer.style){layer=layer.style;} layer.visibility='hidden'; } // --> </script> Code (markup): Thank you so much in advance for any help at all, because I've been struggling for hours trying to make this work, and I'm sure the right person could solve my problem in a matter of minutes.
The meaning of the phrase "strategic popup," eludes me. That code, using "layer" and "eval" is obsolete. But, if you like it, then... This example code uses a button in the pop up to "Don't Show Again". <input type="button value="Don\'t Show Again" onclick="opener.setCookie('pop1',0,opener.expDate);self.close()"> Code (markup): It's up to you, to incorporate it in to your code, if desired. Main document: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Any Title</title> <script type="text/javascript"> var expDate = new Date(); expDate.setTime(expDate.getTime()+365*24*60*60*1000); // one year function setCookie(isName,isValue,dExpires){ document.cookie = isName+"="+isValue+";expires="+dExpires.toGMTString(); } function getCookie(isName){ var cookieStr = document.cookie; var startSlice = cookieStr.indexOf(isName+"="); if (startSlice == -1){return false} var endSlice = cookieStr.indexOf(";",startSlice+1) if (endSlice == -1){endSlice = cookieStr.length} var isValue = cookieStr.substring(startSlice,endSlice).replace(/^.+\=/,""); return isValue; } function initPopups(){ if (!getCookie('pop1')) {popWin1 = window.open("1/pop1.html","","width=200,height=150,top=50,left=400")} if (!getCookie('pop2')) {popWin2 = window.open("1/pop2.html","","width=200,height=150,top=50,left=180")} } onload=initPopups; </script> </head> <body> </body> </html> Code (markup):
that code doesn't work. its blockable. anyone have an answer for this? I'm using the same code (1st example) works wonderfully, easily adjustable and doesn't get blocked. but yes, Id also like it to show once per session as well. any help is appreciated. if not, any other references to flyin popup code?????? Thanks, Trisha