Boardy
Boardy

Reputation: 36217

Strip HTML Encodings from a String

I am working on a project where I have a URL parameter and I am reading this in from jquery.

I then need to display the value of the parameter to the user but I get the HTML encoding as part of the string.

For example if my string is my string I get my%20string.

Below is how I am getting the value from the parameter:

function getParameterValue(parameter)
{
    var pageUrl = window.location.search.substring(1);
    var urlVariables = pageUrl.split('&');

    for (var i = 0; i < urlVariables.length; i++)
    {
        var parameterName = urlVariables[i].split('=');
        if (parameterName[0] == parameter)
        {
            return parameterName[1];
        }
    }
}

Upvotes: 1

Views: 63

Answers (1)

Mathew Thompson
Mathew Thompson

Reputation: 56439

You need to use the Javascript equivalent of decoding the URL: decodeURIComponent():

return decodeURIComponent(parameterName[1]);

Upvotes: 2

Related Questions