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
Susan SarandonOriginal
2024-12-21 02:55:091004browse

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

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!

Statement:
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