Jump to content

Onfirst Load?


Recommended Posts

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...