Home > Web Front-end > JS Tutorial > How Can I Retrieve a Specific GET Parameter Value in JavaScript?

How Can I Retrieve a Specific GET Parameter Value in JavaScript?

Susan Sarandon
Release: 2024-12-21 02:55:09
Original
1002 people have browsed it

How Can I Retrieve a Specific GET Parameter Value in JavaScript?

Obtaining GET Parameter Values in JavaScript

When encountering URLs containing GET parameters, such as "www.test.com/t.html?a=1&b=3&c=m2-m3-m4-m5," retrieving the entire value for the "c" parameter can prove challenging. JavaScript, alone, lacks intrinsic functionality for handling this task.

However, modern browsers and Node.js provide the URL object within the Web API. This object allows for efficient interaction with URLs:

var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; 
var url = new URL(url_string);
var c = url.searchParams.get("c");
console.log(c);
Copy after login

The above is the detailed content of How Can I Retrieve a Specific GET Parameter Value in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template