Last active
August 24, 2024 12:24
-
-
Save ScottKaye/5158488 to your computer and use it in GitHub Desktop.
Hide URL parameters using Javascript's history.replaceState methods. The server (PHP or whatever) will still see it of course, but this script will quickly 'hide' the parameters. Don't use this to hide anything sensitive - there shouldn't be anything sensitive in GET anyway, but I use this to hide various un-pretty things like ?error=invalidPass…
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 characters
function getURLParameter(name) { | |
return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]); | |
} | |
function hideURLParams() { | |
//Parameters to hide (ie ?success=value, ?error=value, etc) | |
var hide = ['success','error']; | |
for(var h in hide) { | |
if(getURLParameter(h)) { | |
history.replaceState(null, document.getElementsByTagName("title")[0].innerHTML, window.location.pathname); | |
} | |
} | |
} | |
//Run onload, you can do this yourself if you want to do it a different way | |
window.onload = hideURLParams; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i made this, seems to do the trick: