Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
cookie not being saved??
Old 05-24-2009, 03:43 PM cookie not being saved??
theohoutman's Avatar
Skilled Talker

Posts: 96
Name: Theo Houtman
Location: Netherlands
Trades: 0
I have some trouble with a warning box on my site. It uses a cookie to hide it when people click on a link. However the box keeps returning when I restart the browser.

simple java funtion:
Quote:
function setCookie()

{

document.cookie = 'hidewarning=true; expires:Sun, 31-May-2099 23:59:59 GMT;';

}


Can someone tell me what I did wrong?
theohoutman is offline
Reply With Quote
View Public Profile Visit theohoutman's homepage!
 
 
Register now for full access!
Old 05-25-2009, 09:02 PM Re: cookie not being saved??
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by theohoutman View Post
Code:
document.cookie = 'hidewarning=true; expires:Sun, 31-May-2099 23:59:59 GMT;';
: should be =.

Code:
function setCookie() 
{ 
 var expDate = new Date();
   
 expDate.setDate( expDate.getDate() + 30 );

 document.cookie = 'hidewarning=true;expires=" + expDate.toGMTString() + ";path=/";
}
logic ali is offline
Reply With Quote
View Public Profile
 
Old 05-26-2009, 07:15 AM Re: cookie not being saved??
theohoutman's Avatar
Skilled Talker

Posts: 96
Name: Theo Houtman
Location: Netherlands
Trades: 0
Still doesn't do what it's supposed to do. Here's the code on my php page with the warning box

In the head section:
Quote:
<?php
function ae_detect_ie()
{
if (isset($_SERVER['HTTP_USER_AGENT']) &&
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;
else
return false;
}
?>
<?php if (ae_detect_ie()) {
if (isset($_COOKIE['hidewarning'])) {}
else { ?>
<script type="text/javascript">
function setCookie()
{
var expDate = new Date();

expDate.setDate( expDate.getDate() + 30 );

document.cookie = 'hidewarning=true;expires=" + expDate.toGMTString() + ";path=/';
}
</script>
<?php }} ?>
The body part:
Quote:
<?php
if (ae_detect_ie()) {
if (isset($_COOKIE['hidewarning'])) {
echo "<!-- IE warning hidden -->\n";
}
else { ?>
<div id="warningbox" align="center">
<table width="960" class="bottom">
<tr>
<td rowspan="2" valign="top">
<img src="/images/warning.png" align="left" alt="" />
</td>
<td class="bottom" align="left">
Beste Internet Explorer gebruiker! De kans bestaat dat U niet goed beveiligd bent en/of U deze site niet goed kunt bekijken door het gebruik van Internet Explorer. Schakel vandaag nog over naar een <u>alternative</u> browser. <a href="/browser.php" class="botlink">Klik hier</a> voor meer informatie voor het <u>alternatief</u> dat wellicht beter voor U zult werken.
</td>
</tr>
<tr>
<td align="right" class="bottom">
<a href="javascript:setCookie()" onclick="document.getElementById('warningbox').sty le.display='none'" class="botlink">klik hier</a> om dit bericht niet meer te tonen.
</td>
</tr>
</table>
</div>
<?php }} ?>
The box is only hidden when the user does not close his/her browser
theohoutman is offline
Reply With Quote
View Public Profile Visit theohoutman's homepage!
 
Old 05-26-2009, 08:56 AM Re: cookie not being saved??
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Quote:
<a href="javascript:setCookie()" onclick="document.getElementById('warningbox').sty le.display='none'" class="botlink">klik hier</a> om dit bericht niet meer te tonen.
Is there a space in the property like that in your actual code?
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 05-26-2009, 10:22 AM Re: cookie not being saved??
theohoutman's Avatar
Skilled Talker

Posts: 96
Name: Theo Houtman
Location: Netherlands
Trades: 0
No that happend after the copy & paste

The hiding of the box (div's) aint the problem. That works wonderfully. It simply keeps re apearing everytime I restart internet explorer.

To see the script in action: http://www.vitanova-info.nl
theohoutman is offline
Reply With Quote
View Public Profile Visit theohoutman's homepage!
 
Old 05-26-2009, 12:28 PM Re: cookie not being saved??
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
As long as you're using PHP, why don't you use the setcookie function instead?
setcookie
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 05-26-2009, 12:44 PM Re: cookie not being saved??
theohoutman's Avatar
Skilled Talker

Posts: 96
Name: Theo Houtman
Location: Netherlands
Trades: 0
As far as I know it would reload the page to call that function. I also like to use this script on multiple locations of the site. Meaning it won't just be a warningbox at the top of a page.

It works with a single session in internet explorer. Can internet explorer be the problem?
theohoutman is offline
Reply With Quote
View Public Profile Visit theohoutman's homepage!
 
Old 05-26-2009, 02:16 PM Re: cookie not being saved??
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
setcookie() does not reload the page. Use it before any HTML is outputted. I personally never set cookies with JavaScript. Cookies weren't even originally intended to be used with JS, and I'm not even sure if there are differences with IE when setting it with JS or not.

I've read that IE sometimes forces cookies to expire when the browser closes if it feels your sites privacy policy isn't inline with the user privacy settings. It may be possible that your browser security settings are causing this.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 05-26-2009, 06:59 PM Re: cookie not being saved??
theohoutman's Avatar
Skilled Talker

Posts: 96
Name: Theo Houtman
Location: Netherlands
Trades: 0
I've added a privacy policy to my site (and man was it a world of pain doing so)

Yet no luck!

I validated it and it seems okay:
http://validator.w3.org/p3p/20020128...ova-info.nl%2F
theohoutman is offline
Reply With Quote
View Public Profile Visit theohoutman's homepage!
 
Old 05-27-2009, 10:42 AM Re: cookie not being saved??
theohoutman's Avatar
Skilled Talker

Posts: 96
Name: Theo Houtman
Location: Netherlands
Trades: 0
Changed the cookie function to:

Quote:
<script type="text/javascript">
function setCookie()
{
exp=new Date();
plusMonth=exp.getTime()+(31*24*60*60*1000);
exp.setTime(plusMonth);
document.cookie='hidewarning=true;expires='+exp.to GMTString();
}
</script>
theohoutman is offline
Reply With Quote
View Public Profile Visit theohoutman's homepage!
 
Reply     « Reply to cookie not being saved??
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30240 seconds with 12 queries