Ok total noob to html. I have this popup script on my forum: And I want to use a cookie so that is only popups up once every 24 hours. How would I do that? Thanks
Thanks that looks like what I need. For this popup I have, this if how I have it set up now: But, the popup still pops up every time the page is viewed. You can see the popup here, its not a typical popup: http://customizepsp.co.uk/forums/index.php?styleid=1 BUT....If I change whats in red and bold to "amt" instead of "Modalbox.show" an actual popup box appears with an error in it, but only once! So Im halfway there. I just need to know why it doesnt work with "body onLoad="Modalbox.show('.." that I have :S Thanks
okey i edited a bit the code save this as cookie.js or whatever you name it var exp = 1; // the number at the left reflects the number of days for the cookie to last // modify it according to your needs function newCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameSG = name + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length,c.length); } return null; } function amt() { var num = readCookie('sancookie1') if (num < 1) { newCookie('sancookie1','testcookie1', exp); Modalbox.show('<form action=\'http://www.gamesites200.com/psp/in.php?id=1850\' method=\'post\' target=\'_blank\' \><img src=\'popup/vote.png\' width=\'500\' height=\'72\'><table width=\'100%\' border=\'0\' cellspacing=\'0\' cellpadding=\'5\'><tr><td align=\'center\' valign=\'top\'><strong>Please reward our efforts by voting for us. </strong><br> All votes are greatly appreciated. <br><br><br> <br></td></tr><tr><td align=\'right\' valign=\'bottom\'><input type=\'submit\' value=\'Yes, I want to vote!\' onclick=\'Modalbox.hide()\' /> <input type=\'button\' value=\'No..\' onclick=\'Modalbox.hide()\' /></td></tr></table></form>', {title: this.title,width: 500}); } } Code (markup): add to your page <script type="text/javascript" src="popup/cookie.js"></script> //to use <body onload="amt();">
Thankyou for taking the time to help me. I created a new .js document with the code you just wrote, and added it to my popup directory. I now have this: And nothing shows up. Have I not done it right? Thanks EDIT: I changed where you wrote "amt" to "Modalbox.show" and the popup showed but still every time the page was viewed. I now changed it back ti amt and the popup doesn't show at all.
the code that show the the popup is in the function amt(); so to call that function amt() { var num = readCookie('sancookie1') if (num < 1) { newCookie('sancookie1','testcookie1', exp); Modalbox.show('<form action=\'http://www.gamesites200.com/psp/in.php?id=1850\' method=\'post\' target=\'_blank\' \><img src=\'popup/vote.png\' width=\'500\' height=\'72\'><table width=\'100%\' border=\'0\' cellspacing=\'0\' cellpadding=\'5\'><tr><td align=\'center\' valign=\'top\'><strong>Please reward our efforts by voting for us. </strong><br> All votes are greatly appreciated. <br><br><br> <br></td></tr><tr><td align=\'right\' valign=\'bottom\'><input type=\'submit\' value=\'Yes, I want to vote!\' onclick=\'Modalbox.hide()\' /> <input type=\'button\' value=\'No..\' onclick=\'Modalbox.hide()\' /></td></tr></table></form>', {title: this.title,width: 500}); } } HTML: use <body onload="amt();"> tried it here in my PC and work perfectly
use this <body onload="amt();"> HTML: instead of this <body onload="amt('<form action=\'http://www.gamesites200.com/psp/in.php?id=1850\' method=\'post\' target=\'_blank\' \><img src=\'http://customizepsp.co.uk/forums/popup/vote.png\' width=\'500\' height=\'72\'><table width=\'100%\' border=\'0\' cellspacing=\'0\' cellpadding=\'5\'><tr><td align=\'center\' valign=\'top\'><strong>Please reward our efforts by voting for us. </strong><br> All votes are greatly appreciated. <br><br><br> <br></td></tr><tr><td align=\'right\' valign=\'bottom\'><input type=\'submit\' value=\'Yes, I want to vote!\' onclick=\'Modalbox.hide()\' /> <input type=\'button\' value=\'No..\' onclick=\'Modalbox.hide()\' /></td></tr></table></form>', {title: this.title,width: 500}); return false;"> HTML:
Hmm well when I visit http://customizepsp.co.uk/forums/index.php?styleid=1 which is where I have added that exact code it does not show up. Does it show for you? I will try on the PC downstairs.. EDIT: Yes!! It worked I am so grateful. I have spent over a week trying to get this to work and thanks to you it is! Thankyou so much.
Ok another problem now, here's what I am currently trying to use: I have changed the code in red and now it is not working. Any ideas?