0

I want to get the value in jquery after the equal sign but i am not been able to get the value this is my url

https://dev.example.com/front-end-pm/?fepaction=newmessage&=Shammy%20Kothari

this is how i am trying to get the value after the = sign

var url      =window.location.href; 
var queryString = url.split('&', 2)[1] || '';

I am getting like this

=Shammy%20Kothari

I just Need

Shammy Kothari

Tayyab Vohra
  • 1,512
  • 3
  • 22
  • 49
  • I think, that can by usefully for you http://www.jquerybyexample.net/2012/06/get-url-parameters-using-jquery.html?m=1 – Marco Mar 10 '19 at 14:57

2 Answers2

1

You need to decode the url using decodeURIComponent()

//var url =window.location.href;

var url ="https://dev.example.com/front-end-pm/?fepaction=newmessage&=Shammy%20Kothari";

var str = decodeURIComponent(url.split('=').pop());
console.log(str);
prasanth
  • 22,145
  • 4
  • 29
  • 53
0

First thing you probably want to change is that the value in your url is not assigned to a name. This would look like this: https://dev.example.com/front-end-pm/?fepaction=newmessage&YOUR_PARAMETER_NAME=Shammy%20Kothari After that you could use URLSearchParams as proposed here. This could look like the following:

const urlParams = new URLSearchParams(window.location.search);
//If you don't want to retrieve the url from the url bar just use: const urlParams = new URLSearchParams('https://dev.example.com/front-end-pm/?fepaction=newmessage&YOUR_PARAMETER_NAME=Shammy%20Kothari');
const myParam = urlParams.get('YOUR_PARAMETER_NAME'); //would be 'Shammy Kothari'
moronator
  • 304
  • 4
  • 11