antonyfal Posted August 18, 2011 Share Posted August 18, 2011 I have a problem running php on some of my html files-- I need a javascript equivalent of this little snipet, it checks if there is a cookie, if there is i can run a div, if there is no cookie then it will run the other div-- Everything i tried didn't work... here is the PHP version: this file is run on a .html file. <?php if(!isset($_COOKIE['letsChat'])){?> <div style="width:89px; height:19px" ><a href="javascript:void(0);" onClick="dhtmlwindow.open('{EMAIL2}', 'iframe', 'http://xxxxxx.com', '{EMAIL2}', 'width=224px,height=237px,resize=0,scrolling=0,center=1');"><font color="#ff0033"><b>CHAT ONLINE</b></font></a></div> <?php } else { ?> <div style="width:89px; height:19px; background-color:transparent;"><font color="#ffffff"><b>CHAT OFFLINE</b></font><div> <?php } ?> // to note: the cookie was set using this code: <script language="javascript"> document.cookie = "ShowFile= 1;" </script> // the value of the cookie is not to important but useful to know how to get/check it.. // is on a html file which is a pat-template file.. so no doctype headers -- regards tony Quote Link to comment https://forums.phpfreaks.com/topic/245154-hi-i-need-a-javascript-equvalent-to-this-php-function-for-cookies/ Share on other sites More sharing options...
antonyfal Posted August 18, 2011 Author Share Posted August 18, 2011 //sorry i mean this script: <script language="javascript"> document.cookie = "letsChat= 1;" </script> this is probably easy for someone out there, i think you looking at it saying!! "why bother", but my javascript is like my Chinese--- just not there! Quote Link to comment https://forums.phpfreaks.com/topic/245154-hi-i-need-a-javascript-equvalent-to-this-php-function-for-cookies/#findComment-1259187 Share on other sites More sharing options...
Omirion Posted August 19, 2011 Share Posted August 19, 2011 You set you cookie like so: The semicolons needs to be outside the quotes document.cookie = "someValue=1"; then you get it with this function function isCoockieSet(value) { var foo = document.cookie.split("="); for (key in foo) { if (foo[key] == value) { return true }; } return false; } You call the function like so: isCookieSet('YourValue') in this case someValue. The func will return true if cookie is there. False otherwise. Just remember to pass a string to isCookieSet PS: i think you looking at it saying!! "why bother", but my javascript is like my Chinese--- just not there! lol dude chill out. Quote Link to comment https://forums.phpfreaks.com/topic/245154-hi-i-need-a-javascript-equvalent-to-this-php-function-for-cookies/#findComment-1259356 Share on other sites More sharing options...
antonyfal Posted August 19, 2011 Author Share Posted August 19, 2011 Ta! Omirion. I got a good idea how it should work from your code.. nice example just this part: isCookieSet('YourValue') ??? How can i write it into the code above? if true return first div, otherwise return other div? Hey i tell you!! the simplest thing, can get so complex!! like this little thing has set me back 3 days, and when i get it will boost me to nearly finished:D.., I'm new at cookies but i just learn't the value of them and how useful and simplistic they are to apply... I would say that this is cookies 1 o 1.. if you or someone can show how to apply this directly to the php example above so i can see it in action with the html in between.. Then all my pieces of puzzle will fall together!! and you will be responsible:'D.. Thanks for this reply.. Tony Quote Link to comment https://forums.phpfreaks.com/topic/245154-hi-i-need-a-javascript-equvalent-to-this-php-function-for-cookies/#findComment-1259568 Share on other sites More sharing options...
Omirion Posted August 19, 2011 Share Posted August 19, 2011 Sorry your code i way to jumbeled for me to sift trough. You need to pass the value you put in the cookie to isSetCookie. Thank proceed as you explained. if(isSetCookie("value")){do whatever} else {do something else} Also your jedi mind tricks will not work on me , i'm from eastern Europe, we don't buy into theese things. Good luck and all... Quote Link to comment https://forums.phpfreaks.com/topic/245154-hi-i-need-a-javascript-equvalent-to-this-php-function-for-cookies/#findComment-1259574 Share on other sites More sharing options...
antonyfal Posted August 19, 2011 Author Share Posted August 19, 2011 lol what Jedi mind tricks?! give me some of that European stuff :'( , i live in south africa, but im Polish thanks again for the code man! Omiran. Awesome! T Quote Link to comment https://forums.phpfreaks.com/topic/245154-hi-i-need-a-javascript-equvalent-to-this-php-function-for-cookies/#findComment-1259580 Share on other sites More sharing options...
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.