Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

97
Views
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
Answer question
Find remote jobs