JavaScript: How to Add A Parameter to the Current URL Without Refreshing

This nifty bit of JavaScript will allow you to add a URL parameter without the page refreshing. This technique uses pushState to achieve this, here’s some more information on manipulating the browser history.

Simply copy and paste the code below onto your desired page and replace ‘?newParameter=1’ with whatever you want your parameter to be:

<script>
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?newParameter=1';
window.history.pushState({ path: newurl }, '', newurl);
</script>
Free Graphics, Icons, Tutorials
Free Graphics Free Christmas Vector Icon Graphics Pack 2017Free Fitness Vector Icons Graphics PackFree Camping Vector Graphics PackFree Summer Graphics PackFree File Icon PackFree Fast Food Vector Graphics
Sharing is caring...
Like & Follow
Share the love, share this page! Facebook Twitter Digg Reddit LinkedIn Pinterest Email
Close [X]
The Web Taylor
1000 Lakeside North Harbour Portsmouth, Hampshire PO6 3EN
02392 123358