Last active
May 25, 2021 10:55
-
-
Save nfreear/ba767c853dced256e85514515dc860ff to your computer and use it in GitHub Desktop.
Display URL parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> <title> URL params test </title> | |
| <style> | |
| body { color: #222; font: 1rem/1.7 sans-serif; margin: .2rem; } | |
| pre { font-size: 1.05rem; } | |
| </style> | |
| <h1> URL parameters </h1> | |
| <pre id="params"></pre> | |
| <p id="url"></p> | |
| <script> | |
| const PRE = document.querySelector('#params'); | |
| const URL = document.querySelector('#url'); | |
| const QUERY = window.location.search.replace(/^\?/, '').split('&'); | |
| const PARAMS = {}; | |
| QUERY.forEach(query => { | |
| const parts = query.split('='); | |
| if (parts && parts[0]) { | |
| PARAMS[parts[0]] = decodeURIComponent(parts[1]) || null; | |
| } | |
| }); | |
| console.warn('URL parameters:', PARAMS, window.location); | |
| PRE.textContent = JSON.stringify(PARAMS, null, '\t'); | |
| URL.textContent = 'URL: ' + window.location.href; | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment