Home > Technical & Creative Skills > Programming, Servers & Scripts

%20 characters appearing for spaces in GET parameters (4)


01-04-2020 11:04 AM #1 manchester (Member)
%20 characters appearing for spaces in GET parameters

Hi,

I'm using the GET parameters in the URL of a landing page. Then using these passed values in my landers to display relevant information.

This is working great until I noticed that any parameter that has a space in the string e.g. "Kuala Lumpur" is being shown with the space character like this = "Kulala%20Lumpur".

My question is, how do make sure that a space is displayed rather than the character?

I had a google around and couldn't find the solution.

Thanks in advance,

Gav


01-04-2020 12:17 PM #2 xander (Member)

The %20 characters are only displayed in the URL. when you retrieved them it will be automatically transformed into spaces


01-04-2020 01:27 PM #3 twinaxe (Senior Moderator)

This is called URL encoding.

What code do you use to display the values on your lander?

Should be shown correctly when it´s decoded before it´s displayed.


01-04-2020 07:34 PM #4 manchester (Member)

Ok, I thought it should decode the %20 into a space character.

But on one of my landers a city is displayed as "Kuala%20Lumpur". And it surprised me.

It's a ripped lander, the GET function was already there but I think I inserted the innerText code to grab the city.

Code:
// GET URL function
        
function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] || ''
    );
}

document.getElementById('city').innerText = getURLParameter('city');
Any ideas?

Thanks


Home > Technical & Creative Skills > Programming, Servers & Scripts