Reputation: 55
By clicking a button, the url has to change but html should stay the same
$('#v-pills-profile-tab').on('click', function (event) {
// change url
// and html remains
})
Upvotes: 1
Views: 138
Reputation: 2232
You can use History.pushState() and WindowEventHandlers.onpopstate
<button id="v-pills-profile-tab"> TEST ME </button>
<script>
$('#v-pills-profile-tab').on('click', function (event) {
window.history.pushState({data: "some data that i will need"}, "", "my-new-url");
});
window.onpopstate = function (e) {
if (e.state) {
console.log(e.state.data);
} else {
window.location.reload();
return;
}
};
</script>
Upvotes: 4
Reputation: 463
For changing url, you can simply do:
window.location = //Your url here
Also, For reloading the page, you can simply use:
window.location.reload()
When you change the url, the page reloads itself on its own. You don't have to reload it
Upvotes: 0