Skip to content

Instantly share code, notes, and snippets.

@sarnobat
Last active September 30, 2017 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarnobat/da32d0a07efc5427f3c6908420920ece to your computer and use it in GitHub Desktop.
Save sarnobat/da32d0a07efc5427f3c6908420920ece to your computer and use it in GitHub Desktop.
Get and Set URL parameter in javascript
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/purl/2.3.1/purl.js"></script>
<script>
// Get the URL parameter
var argName = $.url().param('argName');
// Set the URL parameter
if (argName == null) {
history.pushState(null, null, '/?argName=defaultValue');
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment