Skip to content

Instantly share code, notes, and snippets.

@ScottKaye
Last active August 24, 2024 12:24
Show Gist options
  • Save ScottKaye/5158488 to your computer and use it in GitHub Desktop.
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…
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;
@arcsms
Copy link

arcsms commented Aug 4, 2024

thank you, its very usefull...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment