Jump to content

JavaScript, cookie and SAFARI


djp1988

Recommended Posts

I have a layer on my site, and when you click on it's contents, this js happens:

function saveCookieinfo(){	var now = new Date();	now.setTime(now.getTime() + 1000 * 60 * 60 * 2);	document.cookie = "votetime=1; expires="+now;	document.getElementById("Layer1").style.display = "none";}

and the php of the same page checks for this cookie, if it's there it won't render the layer, until the cookie isn't there (after 2 hours), although this works on all other browsers, I just noticed that safari isn't playing right, it would seem that the php doesn't detect the cookie, or maybe I am setting the cokkie in a way safari doesn't do?My php is the following:

<?php if($_COOKIE['votetime'] != 1){echo '<div id="Layer1"><div class="voterForUs"><a href="..." onclick="saveCookieinfo()" target="_blank"><img border="0" src="..." width="90" height="50"></a><br />...</div></div>';}?>

I have just noticed that in Opera the cookie seems to be killed if the browser is quit, and when you open the browser again, the layer renders, but if you don't quit, and suf the site, the cookie and php are doing what the should and the layer doesn't come back.....AND also, this forum's logo at the top, and ad on the top right, don't appear in safari nor opera on mac.... but the image source in the source of the page is there.... what's up with that ?

Link to comment
Share on other sites

You're using a UNIX timestamp for the cookie expiration, the expiration time should be in the format DD-Mon-YYYY HH:MM:SS GMT. Other than that, inside Safari look for the cookie to verify that it's actually being set.

Link to comment
Share on other sites

in safari, after i supposidly set the cookie, in my preferences I look up this cookie, I see a cookie, but the name isn't the same, it is PHPSESSID, there is no expiration and the value of it I cannot even wonder where it came from, but strange that there is a cookie, that wasn't there before, but it isn't what I want it to beOn comparaison with firefox, I get on that 2 cookies one for PHPSESSID I don't know why, I have not made a session?? and the other is th one i want, so I am seeing that this javascript is not setting a cookie, are there diferent ways to set cookies for safari seen as htis doesn't work?

Link to comment
Share on other sites

ok, that function works, i have cookies ! maybe it is bacause of the expiration date which you told me wasn't good? maybe safari rejects these cookies? in that case how can I dynamically set the expiration date for 2 hours time going from miliseconds to a date in the form of ../../....

Link to comment
Share on other sites

You're using a UNIX timestamp for the cookie expiration, the expiration time should be in the format DD-Mon-YYYY HH:MM:SS GMT. Other than that, inside Safari look for the cookie to verify that it's actually being set.
Hold on, I just realised, I'm not setting the expiration date in miliseconds :
function saveCookieinfo(){	var now = new Date();	now.setTime(now.getTime() + 1000 * 60 * 60 * 2);	document.cookie = "votetime=1; expires="+now;}

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...