jquery - getParameterByName get values store in cookie -
i'm trying grab values in location.querystring object 1 2 values want store them in cookie can pass on api @ checkout process.
function getparameterbyname( name ){ var regexs = "[\\?&]"+name+"=([^&#]*)", regex = new regexp( regexs ), results = regex.exec( window.location.search ); if( results === null ){ return ""; } else{ return decodeuricomponent(results[1].replace(/\+/g, " ")); } } var mc_emailid = getparameterbyname('mc_eid'); var mc_campaignid = getparameterbyname('mc_cid'); var mccookie = new array([]); document.cookie = mccookie; alert(document.cookie);
i stopped sec because don't think i'm doing correctly i'm wanting accomplish. in location.querystring there 2 values need pass on cookie. mc_eid , mc_cid code works fine i'm not sure how target those.
update advice below
// mail chimp id's stored in variable function getparameterbyname( name ){ var regexs = "[\\?&]"+name+"=([^&#]*)", regex = new regexp( regexs ), results = regex.exec( window.location.search ); if( results === null ){ return ""; } else{ return decodeuricomponent(results[1].replace(/\+/g, " ")); } } var mc_emailid = getparameterbyname('mc_eid'); var mc_campaignid = getparameterbyname('mc_cid'); mccookie = "mc_eid=" + mc_emailid + "; mc_cid=" + mc_campaignid; document.cookie = mccookie; var days = 30; var d = new date(); d.settime(d.gettime() + (days*24*60*60*1000)); var expires =";expires="+d.toutcstring(); document.cookie = mccookie + expires + "; path=/";
a cookie string has name , value each cookie name=value; name2=value;
for code like
mccookie = "mc_eid=" + mc_emaild + "; mc_cid=" + mc_campaignid; document.cookie = mccookie;
alerting document.cookie alert whole cookie string. w3schools has functions use cookie name or set one.
to set expire date
var days = 30; var d = new date(); d.settime(d.gettime() + (days*24*60*60*1000)); var expires =";expires="+d.toutcstring();
you want use path
make cookie accessible on whole site. after you've set expires
, mccookie
above should set cookie this
document.cookie = mccookie + expires + "; path=/";
Comments
Post a Comment