Search code examples
javascripthtmlbrowser-historyhtml5-history

How to append a website to a browser's history with javascript?


I'm making a website and we're switching our domain. I want it so that when they log on to the website, it adds a new website with the new domain to their browser history.

I've already tried making a hidden <iframe> and I'm out of ideas.

The main browser they are using is chrome, so cross-browser is not a concern.

But limitations are that we are not allowed to load the page / open it in a new tab/window.


Solution

  • Use the HTML5 History api. To push to history, you’d use:

    history.pushState(null, null, 'http://example.com');

    You’ll probably run into some browser issues though.

    For more info check this out: https://css-tricks.com/using-the-html5-history-api/