javascript cookie problem -
i new javascript.
today tried function found on internet:
function get_cookie ( cookie_name ) { var cookie_string = document.cookie ; if (cookie_string.length != 0) { var cookie_value = cookie_string.match ( '(^|;)[\s]*' + cookie_name + '=([^;]*)' ); return decodeuricomponent ( cookie_value[2] ) ; } return '' ; }
if call function once, works; if call function twice, it's not working.
function onloadthis() { var t = get_cookie('t'); // if add one, not working var s = get_cookie('s'); // more code }
both cookies exist. there workaround make work, or can 2 variable merged in cookie? thank help.
you try instead different regexp:
not
var cookie_value = cookie_string.match ( '(^|;)[\s]*' + cookie_name + '=([^;]*)' );
but
var cookie_value = cookie_string.match ( '([^;]*)[\s]*' + cookie_name + '=([^;]*)' );
Comments
Post a Comment