Last active
May 17, 2024 07:18
-
-
Save clarkhacks/e139f42caaf175844276bff69b41e282 to your computer and use it in GitHub Desktop.
Retrieve Url Parameter Values.
This file contains hidden or 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
function encodeHTML(s) { | |
return s.replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"'); | |
} |
This file contains hidden or 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
function ifPage(url, fx) { | |
if (window.location.pathname.slice(0, -5) == url) { // trailing ".html" | |
fx(); | |
} else if (window.location.pathname == url) { | |
fx(); | |
} | |
} |
This file contains hidden or 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
function paramVal(param) { | |
param = param.replace(/[\[\]]/g, "\\$&"); | |
var regex = new RegExp("[?&]" + param + "(=([^&#]*)|&|#|$)"), | |
results = regex.exec(window.location.href); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
} | |
// url -> https://www.example.com/?ref=facebook | |
// code -> paramVal("ref") returns "facebook" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment