Update Url Without Reloading The Page With jQuery

Share Now

Sample code

jQuery(document).on('ready', function() {
 var variant = $('select.product-single__variants :selected').val();
 console.log( variant );
 var loc = window.location;
 var origin = location.origin;
 var pathname = location.pathname;
 var finalUrl = origin + pathname + "?variant=" + variant;

 //updating URL
 history.pushState({}, null, finalUrl);
});
Picture of Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert