views:

19

answers:

2

I am using cookie plug in my application. where i display some information from cookies. it is working fine with firefox, but have some issues with IE. It works fine if i open a new tab in IE, it shows values from cookies, but if i close IE browser window it clears all cookies. this is not the case with mozilla, every time i open mozilla it shows those specific values from cookies. below is the code i use to set/get cookies.

function setCookies(){<br/>      
   if($('select[id$="ddlFromStation"]')[0].selectedIndex!=0){<br/>
      $.cookie('d_from',$('select[id$="ddlFromStation"]').val());<br/>
   }<br/>
   if($('select[id$="ddlToStation"]')[0].selectedIndex!=0){<br/>
      $.cookie('d_to',$('select[id$="ddlToStation"]').val());<br/>
   }<br/>
   if($('input[id$="txtFromStation"]').val()!=""){<br/>
      $.cookie('i_from',$('input[id$="txtFromStation"]').val());<br/>
   }<br/>
   if($('input[id$="txtToStation"]').val()!=""){<br/>
      $.cookie('i_to',$('input[id$="txtToStation"]').val());<br/>
   }<br/>
   return true;<br/>
}<br/>
$(document).ready(function(){<br/>
 if($.cookie('d_from')!=null){<br/>
    $('select[id$="ddlFromStation"]').val($.cookie('d_from'))<br/>
 }<br/>
 if($.cookie('d_to')!=null){<br/>
    $('select[id$="ddlToStation"]').val($.cookie('d_to'))<br/>
 }<br/>
 if($.cookie('i_from')!=null){<br/>
    $('input[id$="txtFromStation"]').val($.cookie('i_from'))<br/>
 }<br/>
 if($.cookie('i_to')!=null){<br/>
    $('input[id$="txtToStation"]').val($.cookie('i_to'))<br/>
 }<br/>
}); <br/>
A: 

Cookies are volatile - depending on the browser settings, they may get cleared when the browser closes. You can set up Firefox to do this, so it isn't unique to Internet Explorer. However, you may find some benefit to setting a long expiry on the cookies to ask the browser to keep them.

If you want to keep information, you need to do that in a database on your server, as you know it won't be cleared out!

Sohnee
A: 

You are not setting an expiry and by default cookies should expire on browser close. I'm not sure why Mozilla isn't doing this which is the real bug.

Try:

$.cookie(COOKIE_NAME, VALUE, { expires: 10 }); /* Expires in 10 days */
Graphain
Thank you dear, it worked.
azazi