You may use window.URL
class:
new URL(location.href).searchParams.get('year')
// Returns 2008 for href = "http://localhost/search.php?year=2008".
// Or in two steps:
const params = new URL(location.href).searchParams;
const year = params.get('year');
More Related Contents:
- How To Display Images Preview and Title When I Paste in Another Site Like Facebook, Whatsapp, etc
- How do I parse a URL into hostname and path in javascript?
- Refresh image with a new one at the same url
- Detect URLs in text with JavaScript
- JavaScript – Get Portion of URL Path
- Get protocol, domain, and port from URL
- Get the values from the “GET” parameters (JavaScript) [duplicate]
- Convert blob URL to normal URL
- Using the GET parameter of a URL in JavaScript [duplicate]
- How to check if the URL contains a given string?
- Regular expression for URL validation (in JavaScript)
- Go to local URL with Javascript
- Change URL and redirect using jQuery
- Redirecting to a relative URL in JavaScript
- How to escape a JSON string to have it in a URL?
- How to replace url parameter with javascript/jquery?
- Usage of Hash(#) in URL
- What are the differences between history.pushState & location.hash? [closed]
- How to change the URL displayed in the browser without leaving the page
- RegEx to match stuff between parentheses
- Relative URLs in AJAX requests
- Remove fragment in URL with JavaScript w/out causing page reload
- How to download an image with Python 3/Selenium if the URL begins with “blob:”?
- How do I URl encode something in Node.js?
- Javascript-Setting background image of a DIV via a function and function parameter
- How to assign a domain name to node.js server? [duplicate]
- get url after “#” in express.js middleware request
- Why is “javascript:” pseudo-protocol stripped from URL bar when pasted?
- Extract keyword from Google search in Javascript
- How could I change window’s location without reloading and # hack?