Search code examples
javascripthtmljqueryonbeforeunloadwindow.location

how do I change the url of my site before unload?


So I have a page that is navagated through by clicking on tabs that change what is displayed in the body of the website, and when you go to a new tab (in the site) it changes the url. e.g I'm in the home tab, and the url is changed to https://a.website.com/home, then i go to the changelog tab, and the url is changed to https://a.website.com/changelog. niiether of these urls actually exist, so how would I make it so when the user reloads they are directed to https://a.website.com, not to a page not found error page? possibly using window.onbeforeunload?


Solution

  • Mark the tab that is being used as a parameter of the page:

    https://a.website.com?tab=home
    https://a.website.com?tab=changelog
    

    Then, on your page you can decide which tab to show.