Last active
January 5, 2025 10:33
-
-
Save excalq/2961415 to your computer and use it in GitHub Desktop.
Revisions
-
excalq revised this gist
Mar 19, 2024 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,12 @@ // 2024 Update, use URLSearchParams [https://caniuse.com/urlsearchparams] export function createQueryString2(name: string, value: string, searchParams: any) { const params = new URLSearchParams(searchParams); params.set(name, value.toLowerCase()); return params.toString(); } // ---- Original 2012 version, when browsers really sucked ---- // Explicitly save/update a url parameter using HTML5's replaceState(). function updateQueryStringParam(param, value) { baseUrl = [location.protocol, '//', location.host, location.pathname].join(''); -
excalq revised this gist
Jun 20, 2012 . 1 changed file with 17 additions and 18 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,19 @@ // Explicitly save/update a url parameter using HTML5's replaceState(). function updateQueryStringParam(param, value) { baseUrl = [location.protocol, '//', location.host, location.pathname].join(''); urlQueryString = document.location.search; var newParam = key + '=' + value, params = '?' + newParam; // If the "search" string exists, then build params from it if (urlQueryString) { keyRegex = new RegExp('([\?&])' + key + '[^&]*'); // If param exists already, update it if (urlQueryString.match(keyRegex) !== null) { params = urlQueryString.replace(keyRegex, "$1" + newParam); } else { // Otherwise, add it to end of query string params = urlQueryString + '&' + newParam; } } window.history.replaceState({}, "", baseUrl + params); } -
excalq created this gist
Jun 20, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ // Explicitly save/update a url parameter using HTML5's replaceState(). // Works for HTML5 supporting browsers. function updateQueryStringParam(param, value) { baseUrl = [location.protocol, '//', location.host, location.pathname].join(''); urlQueryString = document.location.search; var newParam = key + '=' + value, params = '?' + newParam; // If the "search" string exists, then build params from it if (urlQueryString) { keyRegex = new RegExp('([\?&])' + key + '[^&]*'); // If param exists already, update it if (urlQueryString.match(keyRegex) !== null) { params = urlQueryString.replace(keyRegex, "$1" + newParam); } else { // Otherwise, add it to end of query string params = urlQueryString + '&' + newParam; } } window.history.replaceState({}, "", baseUrl + params); }