Maisara-WD Posted March 30, 2009 Share Posted March 30, 2009 Hi guys...I want an alert to be shown when the site firstly open.. and NOT TO repeat showing when the index page is re-loaded...I think it's related some how to cookies.. but I'm not good at cookies at all...how can I do it...thx Link to comment Share on other sites More sharing options...
Ingolme Posted March 30, 2009 Share Posted March 30, 2009 Taken from the W3Schools tutorial: function getCookie(c_name){if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } }return "";}function setCookie(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());} Then make your custom function: function alertOnce() { visit=getCookie('visit'); if (visit != 1) { alert("Message"); setCookie('visit',1,365); }} And finally, perform the function when the window loads: window.onload = alertOnce; All of the previous code must go between script tags in the <head> of the document. Link to comment Share on other sites More sharing options...
Maisara-WD Posted March 30, 2009 Author Share Posted March 30, 2009 thx alot Ingolome Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.