who can use js get url's parameter

Any problem with javascript can be discussed here.
Post Reply
ami38701
Posts: 62
Joined: Wed Aug 01, 2007 6:42 am

who can use js get url's parameter

Post by ami38701 »

an url like this:http://www.example.com/1.html?para1=ddd&para2=ccc

use js to get the values..

how to????


Image
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

Javascript does not have native access for GET parameter, so here is the other way how to obtain GET parameter

Code: Select all

<script language="JavaScript" type="text/javascript"> 
function getParam(strParamName)
{
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("?") > -1 )
    {
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
        {
            if (aQueryString[iParam].indexOf("=") > -1 )
            {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
    return strReturn;
} 
</script> 
usage:

Code: Select all

getParam('parameter')
Image
arash
Posts: 12
Joined: Thu Feb 26, 2009 9:21 pm

Post by arash »

tnx u so much for ur topic!:);)
Post Reply