Yesterday, I encountered a possible candidate for the "Daily Worse than Failure (WTF)": This URL: https://www.mappen.com/geoblocked.html#=tytutyutr_IO (or something equivalent)
So you (the developer of the page in question) don't know how URIs work and couldn't be bothered to search the Web for the relevant RFC (2396; see section #3: "URI Syntactic Components"). Why not write your own unnecessary and shoddy implementation? What the heck? As long as it works, who cares that you've gone about it the wrong way? Well, I, for one, do. The IETF probably do, too, since they wouldn't have published the RFC if they didn't. Standards exist for a reason (and not so that you can ignore them when you feel like it).
"For every problem, there is a solution that is simple, obvious and wrong." — H. L. Mencken
Jeepers, a quick search for "queryString" and "UrlParams" gives this fairly standard code, as found on SitePoint:
const queryString = new URLSearchParams(window.location.search);
const val = queryString.get('key');
If you wanted to, you could even extend it to this, in a shim:
if ((typeof window.location.queryString) !== 'function') {
window.location.queryString = function (key) {
const query = new URLSearchParams(window.location.search);
if (key === null) return query; // or return '';, if you prefer
else return query.get('key');
};
}
Then, to get the value of something in a queryString, for example, videoID in https://www.mappen.com/geoblocked.html?videoID=tytutyutr_IO (note the use of a question mark and parameter name):
const videoID = window.location.queryString ("videoID");
That's how it works on every other site that's ever needed to retrieve key-value pairs from a URL using JavaScript, so why is this particular developer so special? Somebody please fetch me my LART and dox this moron, so I can stop having nightmares about how and why they did what they did! I don't even want to know what the code looks like, given the outward appearance of the implementation.
Post thumbnail: Photo by Brett Sayles on Pexels