Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get url parameters javascript

const url = new URL(window.location.href);
const parameterValue = url.searchParams.get('pramaName');
console.log(parameterValue);
Comment

read url param data in javascript

var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("c");
console.log(c);
 Run code snippet
Comment

getting url parameters with javascript

<!DOCTYPE html>
<html>

<head>
	<title>How To Get URL Parameters using JavaScript?</title>
</head>

<body>
	<h1 style="color: blue;">
		Softhunt.net
	</h1>
	<b>
		How To Get URL Parameters
		With JavaScript?
	</b>
	<p> The url used is:
    https://www.example.com/login.php?a=Softhunt.net&b=Welcome&c=To Our Website
	</p>

	<p> Click on the button to get the url parameters in the console. </p>

	<button onclick="getParameters()"> Get URL parameters </button>
	<script>
	function getParameters() {
		let urlString =
"https://www.example.com/login.php?a=Softhunt.net&b=Welcome&c=To Our Website";
		let paramString = urlString.split('?')[1];
		let queryString = new URLSearchParams(paramString);
		for(let pair of queryString.entries()) {
			console.log("Key is:" + pair[0]);
			console.log("Value is:" + pair[1]);
		}
	}
	</script>
</body>

</html>
Comment

getting url parameters with javascript

<!DOCTYPE html>
<html>

<head>
	<title> How To Get URL Parameters using JavaScript? </title>
</head>

<body>
	<h1 style="color:blue;">
		Softhunt.net
	</h1> <b>
		How To Get URL Parameters
		With JavaScript?
	</b>
  <b>By Separating and accessing each parameter pair</b>
	<p> The url used is:
    https://www.example.com/login.php?a=Softhunt.net&b=Welcome&c=To Our Website
	</p>

	<p> Click on the button to get the url parameters in the console. </p>

	<button onclick="getParameters()"> Get URL parameters </button>
	<script>
	function getParameters() {
		let urlString =
"https://www.example.com/login.php?a=Softhunt.net&b=Welcome&c=To Our Website";
		let paramString = urlString.split('?')[1];
		let params_arr = paramString.split('&');
		for(let i = 0; i < params_arr.length; i++) {
			let pair = params_arr[i].split('=');
			console.log("Key is:" + pair[0]);
			console.log("Value is:" + pair[1]);
		}
	}
	</script>
</body>

</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript parse date dd/mm/yyyy hh:mm:ss 
Javascript :: converting object to an array in javascript 
Javascript :: javascript array remove middle 
Javascript :: discord.js get the message before 
Javascript :: stringify json javascript 
Javascript :: replace each string by another string javascript 
Javascript :: chart js delete old chart 
Javascript :: apps script toast 
Javascript :: check checkbox by jquery 
Javascript :: npm react dropdown 
Javascript :: js check if a variable is an array 
Javascript :: anagram program in javascript 
Javascript :: remove element from array javascript by index 
Javascript :: javascript indentation 
Javascript :: click select option to update div jquery 
Javascript :: how check if a form date is before today javascript 
Javascript :: javascript get element by id and class 
Javascript :: ternary operator javascript 
Javascript :: exist element js 
Javascript :: args slice discord.js 
Javascript :: How to test useEffect in react testing library 
Javascript :: jquery datatable table header not increasing on expanding 
Javascript :: on focus out javascript 
Javascript :: use effect react 
Javascript :: javascript remove object key 
Javascript :: getserversideprops nextjs 
Javascript :: array put value in index 
Javascript :: require mongoose 
Javascript :: how to update node js through terminal 
Javascript :: use these instead of a for loop javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =