Created
June 26, 2017 17:36
-
-
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.
This file contains hidden or 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
| <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