dzhax Posted September 28, 2009 Share Posted September 28, 2009 I have this code for making a cookie. function popup_show(remove_id){ document.cookie = 'remove=something';} that will make the cookie remove with a value of somthingnow if i do this function popup_show(remove_id){ document.cookie = remove_id;} or function popup_show(remove_id){ document.cookie = escape(remove_id);} It does not set the cookie. It leaves it NULL.remove_id = 'remove=11' when sentCan someone help? Link to comment Share on other sites More sharing options...
Ingolme Posted September 28, 2009 Share Posted September 28, 2009 If you escape it, the '=' will lost its meaning. Try encodeURI() rather than escape.Try checking what the parameter is inside the function: function popup_show(remove_id) { alert(remove_id); document.cookie = remove_id;} Link to comment Share on other sites More sharing options...
dsonesuk Posted September 28, 2009 Share Posted September 28, 2009 typical cookie setting and getting script: function set_cookie( name, value, exp_y, exp_m, exp_d, path, domain, secure ) { var cookie_string = name + "=" + escape ( value ); if ( exp_y ) { var expires = new Date ( exp_y, exp_m, exp_d ); cookie_string += "; expires=" + expires.toGMTString(); } if ( path ) cookie_string += "; path=" + escape ( path ); if ( domain ) cookie_string += "; domain=" + escape ( domain ); if ( secure ) cookie_string += "; secure"; document.cookie = cookie_string; }function get_cookie(cookie_name){ var results = document.cookie.match( '(^| ?' + cookie_name + '=([^;]*)(;|$)' ); if ( results ) return ( unescape ( results[2] ) ); else return null;}function setthiscookie(remove_id){ set_cookie("remove_id", remove_id);}function getthiscookie() { var thiscookievalue = get_cookie("remove_id"); } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.