0

I need get only this part of current url and redirect after 5 seconds...

example of current url:

http://www.page.com/?archive=filename

i need get only filename and put in javascript code

here my code:

<script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
<script type="text/javascript">
var country,url;
country = geoip_country_code()
if(country=="US"){
    url="http://www.page.com/1.php?archive=filename";
} else if (country == "UK") {
    url="http://www.page.com/2.php?archive=filename";
} else if (country == "ES") {
    url="http://www.page.com/3.php?archive=filename";
}
setTimeout("location.href = url;",5000);
</script>

please i need help with this code, thanks.

user2893064
  • 11
  • 1
  • 1
  • Is there any possibility that the URL you're trying to pick apart might be different? – Kehlan Krumme Oct 18 '13 at 23:25
  • possible duplicate of [How can I get query string values?](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values) – Barmar Oct 18 '13 at 23:38

2 Answers2

1

you can use the code posted here:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var country, 
    url, 
    codemap = { 
        US: 1,
        UK: 2,
        ES: 3
    };

url = "http://www.page.com/" + codemap[geoip_country_code()] + ".php?archive=" + getParameterByName('archive');

setTimeout(function () { location.href = url; },5000);
Community
  • 1
  • 1
Nicolás Straub
  • 3,322
  • 5
  • 19
  • 42
0

Here's a previous question on parsing query strings in JavaScript. That one's already marked as a duplicate, so there's undoubtedly more info out there. If this doesn't help, the keywords you want to search for are "Parse query string in JavaScript".

Parse query string in JavaScript

Community
  • 1
  • 1
Rebecca Campbell
  • 735
  • 1
  • 6
  • 14