0

I need a solution to parse the value in the URL split between %2526_ga%253d and &wct then append &_ga= + the parsed value to the end of the same URL.

This is my URL, which is always different but %2526_ga%253d and &wct is always the same. http://www.example.com/wa=wsignin1.0%2526_ga%253d1.193373933.1506621463.1391436765&wct=2014-04-25T19

The end result would be: http://www.example.com/wa=wsignin1.0%2526_ga%253d1.193373933.1506621463.1391436765&wct=2014-04-25T19&_ga=1.193373933.1506621463.1391436765

I completed my solution and this works:

var gacookie = window.location.search.match('_ga%253d(.+)&wct=');
var url = window.location.href;

if (url.indexOf('_ga') > -1) {
        url += '&_ga=' + gacookie[1]
        parent.location.hash = url
        var hash = location.hash.replace('#', gacookie[1]); 
        if(hash != '') {
        location.hash = '&_ga=' + gacookie[1];
    }
}
1
  • What code have you tried? What solutions have you looked at so far? Commented Apr 25, 2014 at 20:16

2 Answers 2

1

You can do it with a RegEx:

var url = 'http://www.example.com/wa=wsignin1.0%2526_ga%253d1.193373933.1506621463.1391436765&wct=2014-04-25T19';
var value = url.match('_ga%(.+)&wct=');
url = url + "&_ga=" + value[1];

You should probably add some validation logic too...

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. This helped me with the match. I updated my script with a solution, but I don't know how to do it without the page refresh.
0

Here is the finished result. Thank you @Mattias for helping me with the match.

var gacookie = window.location.search.match('_ga%253d(.+)&wct=');
var url = window.location.href;

if (url.indexOf('_ga') > -1) {
        url += '&_ga=' + gacookie[1]
        parent.location.hash = url
        var hash = location.hash.replace('#', gacookie[1]); 
        if(hash != '') {
        location.hash = '&_ga=' + gacookie[1];
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.