/    Sign up×
Community /Pin to ProfileBookmark

Set Cookie – Dynamic URLParameter Name

Hi there guys…

I’ve been strugling looking for a way to set a cookie if a URL parameter is persent. The problem is, the name of the URL parameter is half dynamic.

The URL would be: “http://zzzz.test.bbbb/index.html?transaction[XXXX]=YYYYY

The XXXX is the userID that will change depending on the customer and YYYY is the actual value (transaction number).

I have the following code but it won’t recognize the brakets nor what is inside. How can I set it to recognize the URL parameter including the brakets and the dynamic userID within the brakets?

====================================================

function URLparam(name) {
return unescape(
(RegExp(name + ‘=’ + ‘(.+?)(&|$)’).exec(location.search)||[,null])[1]
);
}

if (URLparam(“transaction”) !== null && !get_cookie (“Transacion_ID”)) {
set_cookie (“Transacion_ID”, URLparam(“transaction”));
}

if (get_cookie (“EX_Transacion_ID”)) {
console.log(get_cookie (“transaction”));
}

});

====================================================

Any hint would be much appreciated.

Thanks!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@adrian_m123authorSep 23.2014 — Correction, this is the code:

====================================================

function URLparam(name) {

return unescape(

(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]

);

}

if (URLparam("transaction") !== null && !get_cookie ("Transacion_ID")) {

set_cookie ("Transacion_ID", URLparam("transaction"));

}

if (get_cookie ("Transacion_ID")) {

console.log(get_cookie ("transaction"));

}

});

====================================================
×

Success!

Help @adrian_m123 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...