2
 function getURLParameter(url, name) {
 return (RegExp(name + '=' + '(.+?)(&|$)').exec(url)||[,null])[1];
 }

This function returns parameter's value receives url and parameter's name.

I want to change this function returns parameter's all name and value receives url.

How can I modify?

asked Mar 8, 2019 at 5:16
1

2 Answers 2

4

Hope this helps

function getURLParams(url) {
 return Object.fromEntries(new URL(url).searchParams.entries());
}
var params = getURLParams('https://www.google.com/search?q=query+string&oq=query+string&aqs=chrome..69i57j69i60l2j0l3.10413j0j7&sourceid=chrome&ie=UTF-8');
console.log(params);
console.log(params['ie']);

answered Mar 8, 2019 at 5:45

Comments

1
function getUrlVars() {
 var vars = [], hash;
 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
 for (var i = 0; i < hashes.length; i++) {
 hash = hashes[i].split('=');
 vars.push(hash[0]);
 vars[hash[0]] = hash[1];
 }
 return vars;
}

the to get your required value use

getUrlVars()["YourParameterInQueryString"]
answered Mar 8, 2019 at 5:59

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.