Skip to content

Instantly share code, notes, and snippets.

@FrankFonts
Created June 14, 2022 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankFonts/44b325f4b94cfa2bd56435b5d5016d30 to your computer and use it in GitHub Desktop.
Save FrankFonts/44b325f4b94cfa2bd56435b5d5016d30 to your computer and use it in GitHub Desktop.
URL First Parameter Detection
// 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
: "";
};
@FrankFonts
Copy link
Author

Quite primitive...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment