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.
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>
Wizard Posted September 4, 2010 Posted September 4, 2010 Also: http://w3schools.com/js/js_cookies.asp
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now