“Paramètres URL de l'analyse JavaScript” Réponses codées

Paramètres URL de l'analyse JavaScript

let url = new URL("https://www.codegrepper.com?s=cool+beans&user_id=4");                                                  
let urlParams = new URLSearchParams(url.search); 
console.log(urlParams.get('s'));//cool beans
console.log(urlParams.get('user_id'));//4
Friendly Hawk

Paramètre JS Get URL

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const code = urlParams.get('code')
Awful Anaconda

Obtenir des paramètres URL avec 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>
Unsightly Unicorn

obtenir des paramètres de l'URL

www.test.com/t.html?a=1&b=3&c=m2-m3-m4-m5 
Cloudy Cod

Obtenir des paramètres URL avec 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>
Unsightly Unicorn

Réponses similaires à “Paramètres URL de l'analyse JavaScript”

Questions similaires à “Paramètres URL de l'analyse JavaScript”

Plus de réponses similaires à “Paramètres URL de l'analyse JavaScript” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code