From bbc1fb852fdc4e82450db88a29bd9cc1e9284bde Mon Sep 17 00:00:00 2001 From: Jonas Leder Date: Fri, 25 Mar 2022 12:23:41 +0100 Subject: [PATCH] rewrite get parameter function --- js/viewPost.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/js/viewPost.js b/js/viewPost.js index dfd5dd1..be5bda8 100644 --- a/js/viewPost.js +++ b/js/viewPost.js @@ -2,18 +2,12 @@ if(window.location['pathname'] == "/post.html"){ loadPost(); } - -function getParameter(key) { - - // Address of the current window - let address = window.location.search - - // Returns a URLSearchParams object instance - let parameterList = new URLSearchParams(address) - - // Returning the respected value associated - // with the provided key - return parameterList.get(key) +// return the value of the get parameter with the given name +function getParameter(name) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); + var results = regex.exec(location.search); + return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } async function loadPost() {