Created
June 14, 2022 10:42
-
-
Save FrankFonts/44b325f4b94cfa2bd56435b5d5016d30 to your computer and use it in GitHub Desktop.
URL First Parameter Detection
This file contains 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
// get the FIRST url parameter | |
// between the start of query string (? excluded) | |
// and the first separator (& excluded) | |
"use strict"; | |
window.onload = () => { | |
// Optional Chaining and Nullish Coalescing | |
// No IE support at all | |
// let id = window.location.href?.split('?')[1]?.split('&')[0] ?? ''; | |
// IE compatible | |
let id = window.location.href.split("?")[1] | |
? window.location.href.split("?")[1].split("&")[0] | |
: window.location.href.split("?")[1] | |
? id | |
: ""; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quite primitive...