I always use php to set a cookie but I had this example from a long time ago. Also you need to rememeber if they have thier javascript turned off in thier browser it won't work, but with php it will.
http://byrondallas.heliohost.org/java/if_s...ent-cookie.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>Untitled Document</title>
<script type="text/javascript">
// set cookie
document.cookie="cookiename="playsong";
//" get only cookie name
function get_cookie ( cookiename ) {
var results = document.cookie.match ( '(^|;) ?' + cookiename + '=([^;]*)(;|$)' );
if ( results )
return ( unescape ( results[2] ) ); else
return null;
}
</script>
</head>
<body text="#000000" bgcolor="#FFFFFF">
<script language="JavaScript">
var cookie_text = get_cookie ( "cookiename" );
document.write("The Cookie name is ");
document.write(cookie_text);
document.write("<p>");
if (cookie_text == 'playsong')
{
document.write("<b>Hello World!</b>");
}
else
{
document.write("<b>CODE IF COOKIE DOES NOT EXIST</b>");
}
</script>
</body>
</html>