Skip to content

Instantly share code, notes, and snippets.

@sarnobat

sarnobat/url_param.js

Last active Sep 30, 2017
Embed
What would you like to do?
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