1

Could someone recommend a way to get page name from a url using JavaScript?

For instance if I have:

http://tulyita.hu/LikeGame/Game.html?like=100

I just need to get "100" string

Thanks!

2 Answers 2

1

how about this:-

var index = yourstring.lastIndexOf("=") + 1;
var filename = yourstring.substr(index);
Sign up to request clarification or add additional context in comments.

Comments

1

To TRY

alert(getURLParameters("http://tulyita.hu/LikeGame/Game.html?like=100","like"));

Others

alert(getURLParameters("http://tulyita.hu/LikeGame/Game.html?like=100&share=4","share"));

alert(getURLParameters("http://tulyita.hu/LikeGame/Game.html?like=100&hits=29","hits"));

Use this

   function getURLParameters(sURL , paramName) 
    {

    if (sURL.indexOf("?") > 0)
    {
       var arrParams = sURL.split("?");         
       var arrURLParams = arrParams[1].split("&");      
       var arrParamNames = new Array(arrURLParams.length);
       var arrParamValues = new Array(arrURLParams.length);     
       var i = 0;
       for (i=0;i<arrURLParams.length;i++)
       {
        var sParam =  arrURLParams[i].split("=");
        arrParamNames[i] = sParam[0];
        if (sParam[1] != "")
            arrParamValues[i] = unescape(sParam[1]);
        else
            arrParamValues[i] = "No Value";
       }

       for (i=0;i<arrURLParams.length;i++)
       {
                if(arrParamNames[i] == paramName){
            //alert("Param:"+arrParamValues[i]);
                return arrParamValues[i];
             }
       }
       return "No Parameters Found";
    }

}

REF:How to get the value from the GET parameters?

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.