Get the query string of a URL (JavaScript)
Getting the query string of a URL in JavaScript:
HTML code:
<div class="example"></div>
JavaScript code:
<script>
// Getting the query string of a URL
var queryString = window.location.search;
// Printing the result
document.querySelector('.example').textContent = queryString;
</script>
Links
- How to retrieve GET parameters from JavaScript [duplicate] https://stackoverflow.com/questions/5448545/how-to-retrieve-get-parameters-from-javascript
- Location: search property developer.mozilla.org/en-US/docs/Web/API/Location/search
Browser support
- Windows
- Edge 12.0+
- Firefox 53.0+
- Google Chrome 1.0+
- Opera 12.1+
- Linux
- Firefox 53.0+
- Google Chrome 1.0+
- Opera 12.1+
- iOS
- Safari 1.0+
- Android
- Samsung Internet 1.0+
- Chrome 18.0+
- Firefox 53.0+
- Opera 12.1+