Need a javascript that will capture cookie from _document.cookie and then pass it to a variable. Also need to strip away some data from cookie. . I only need the portion that says ""AMCVS_C7C319A0574F094D7F000101%40AdobeOrg=1"pass this value to a variable called eVar.. Example of cookie is at the bottom. Im thinking script should be something like this. function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca; while (c.charAt(0) == ' ') { c = c.substring(1); } I'm thinking somewhere in here is where I would strip away the unwanted portion. } } return ""; } Code (markup): Please help not sure how to go about this.. Thanks. Here is an example of a cookie. "AMCVS_C7C319A0574F094D7F000101%40AdobeOrg=1; AMCV_C7C319A0574F094D7F000101%40AdobeOrg=-1248264605%7CMCIDTS%7C17037%7CMCMID%7C56086522608320454022024251645676171677%7CMCAAMLH-1472181159%7C7%7CMCAAMB-1472583043%7CNRX38WO0n5BH8Th-nqAG_A%7CMCOPTOUT-1471985443s%7CNONE%7CMCAID%7C2BD5B8EF85078B17-60000106C03A19F8; Code (markup):
Is the part you need always at the beginning of the cookie? If so all you need to do after the split is a simple ca[0] (with a trim if you don't want the spaces)
If I understood correctly what you need: function getCookie(cName) { var cookieArray = document.cookie.split(";"); for (var i = 0; i < cookieArray.length; i++) { if (cookieArray[i].indexOf(cName) !== -1) { return cookieArray[i].substring(cookieArray[i].indexOf("=") + 1); } } return; } var cName = "AMCVS_C7C319A0574F094D7F000101%40AdobeOrg"; alert(getCookie(cName)); Code (markup):