1

I've been racking my brain about this and I can not figure out why this isn't working.

I have a link that looks like this:

http://exampledomain.com/page.html?var1=42&var2=hello

and page.html is calling a javascript page that says:

alert(var1);
alert(var2);

But when I test the page all I get is function Number() { [native code] }

Anybody know what I could be going wrong?

BryanH
  • 5,826
  • 3
  • 34
  • 47
  • possible duplicate of [Get query string values in JavaScript](http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript) – D'Arcy Rittich Jul 25 '12 at 19:08
  • 2
    You're passing `GET` parameters. Javascript doesn't "see" `GET` parameters, it can however read `window.location` and parse it. – Adi Jul 25 '12 at 19:08
  • query string value can not retried directly. either u did not post complete question – xkeshav Jul 25 '12 at 19:09
  • See also: http://stackoverflow.com/a/901144/86860 – Nate Jul 25 '12 at 19:11

1 Answers1

0

Use this function:

var GET = function(query){
    var varsArray = [],
    url = window.location.search.match(/[^\?\&]+/g),
    vars = [];
    for(var i=0;i<url.length;i++)
        if(/\=/.test(url[i]))
            vars.push(url[i]);
    for(var i=0;i<url.length;i++){
        var This = url[i].split('=');
        varsArray[This[0]] = This[1];
    }
    return query ? varsArray[query] : (varsArray || '');
}
Danilo Valente
  • 11,270
  • 8
  • 53
  • 67