Skip to content

Instantly share code, notes, and snippets.

@NickDeckerDevs
Created June 26, 2017 17:36
Show Gist options
  • Select an option

  • Save NickDeckerDevs/5cfec4a9b14b98d3edd6fd32692ace25 to your computer and use it in GitHub Desktop.

Select an option

Save NickDeckerDevs/5cfec4a9b14b98d3edd6fd32692ace25 to your computer and use it in GitHub Desktop.
Small script to show how you can push items into the URL but not actually reload the page.
<form>
<p>You can type a name into the field below and it will change your browser path upon clicking Change URL button. I have defaulted with a value in the input to make testing quicker.</p>
<label>New URL: </label>
<input type="text" id="name" value="Nicholas Decker">
<input type="button" id="change-url" value="Change URL">
</form>
<script>
$(document).ready(function() {
$('#change-url').on('click', function() {
var name = $('#name').val();
var title = 'About ' + name;
var new_page = '/about-us-test?name=' + name.replace(/ /g, '-');
window.history.pushState("string", title, new_page);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment