alteisenriese Posted September 3, 2010 Posted September 3, 2010 How to make a javascript file which when the cookie is set it will do something. Quote
Byron Posted September 3, 2010 Posted September 3, 2010 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> Quote
Wizard Posted September 4, 2010 Posted September 4, 2010 Also: http://w3schools.com/js/js_cookies.asp Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.