Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

98
Vistas
How to read URL Query Parameter where value has + for spaces

I am reading query parameters using below method

function getParameterByName(name, url = window.location.href) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
    results = regex.exec(url);
if (!results) return '';
if (!results[2]) return '';
result = escape(results[2]);
return decodeURIComponent(result.replace(/\+/g, ' '));

URL is in below format http://loalhost:8080?param1=value1+value2

But problem with above method is if either in value1 and value2 contains genuine + character then that character also is replaced with space.

Can someone help me with this issue?

I need approach to solve above issue in plain javascript.

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos