skip to Main Content

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
})

2

Answers


  1. For changing url, you can simply do:

    window.location = //Your url here
    

    Also,
    For reloading the page, you can simply use:

    window.location.reload()
    

    Note

    When you change the url, the page reloads itself on its own. You don’t have to reload it

    Login or Signup to reply.
  2. 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>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search