Skip to main content
Inspiring
November 27, 2006
Question

javascript and url

  • November 27, 2006
  • 3 replies
  • 401 views
Can javascript read a variable passed in a url? I can read the entire url with document.URL, but I need a specific variable.
    This topic has been closed for replies.

    3 replies

    Participating Frequently
    November 27, 2006
    You can also try out this function.

    function getURLParams(paramName)
    {
    var sRegExp = "[\\?&]"+paramName+"=([^&#]*)";
    var RegExpObj = new RegExp(sRegExp);
    var sURL = window.location.href;
    var arrParamVal = RegExpObj.exec(sURL);
    if(arrParamVal == null)
    return "";
    else
    return arrParamVal[1];
    }

    Here ParamName is the URL parameter name.

    Thanks

    Sankalan
    (www.mindfiresolutions.com)
    Inspiring
    November 27, 2006
    Thank you very much, I shall try it.
    Participating Frequently
    November 27, 2006
    I posted a blog entry on this...

    http://axel.cfwebtools.com/index.cfm/2006/11/4/How-to-get-a-query-string-out-of-javascript


    there is a litlle bit more to it than just this function, but not much at all... check out the blog entry