-5

URL: http://example.com/?a=1&b=2&c=3?reco_id=xxxx

xxxx is the actual value (transaction number).

  1. set a cookie "xxxx"
  2. move oder page > call "reco_id"
Jongwon Bae
  • 1
  • 1
  • 1
  • Please be more specific about your problem: Do you have trouble getting the value from the url? Do you have trouble setting the cookie value? Do you have trouble navigating to the desired target url? – Filburt Nov 11 '16 at 14:44

2 Answers2

1

You could access the query part of the url via document.location.search and the cookie string via document.cookie and modify the latter. To achieve this a cookie library like https://github.com/js-cookie/js-cookie might be helpful.

But JavaScript has no built in helpers to read individual query parameters from the complete query string. Check out this question: How to get the value from the GET parameters?

Community
  • 1
  • 1
Mauro Bringolf
  • 528
  • 5
  • 14
0

First you need to extract the cookie parameter from the URL. Unfortunately, browser JS provides no built in method to parse URLs. I prefer using jQuery.parseParams.

Then you can use document.cookie to store the cookie value. Setting cookie in this way can be cumbersome, so you can use a library such as jQuery.cookie

Then you can do something like this:

var params = $.parseParams(document.location.search);
$.cookie('reco_id',params['reco_id']);

Additional resources:

  1. How do I set/unset cookie with jQuery?
  2. If you are not using jQuery, there are some good vanilla JS methods outlined here :
Community
  • 1
  • 1
recrsn
  • 450
  • 5
  • 12