简体   繁体   中英

How to get the value of url after = sign in jQuery

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

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); 

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM