I use document.open () + write () + close () to create a new page from the client. This works, but it will replace the current history item with a new page, so when the user clicks back, they donβt see the page they were just on. Example:
- On the home page
- Click the button to go to the page shown below.
- Click on the click me button on this page.
- Click "Back" - this returns the user to the home page, which I do not want.
I tried to insert a history element with history.pushState() , but that will not work either. This allows the document.open page to have a new URL. Clicking back returns the user to the URL of the page I want to display, but this is still a "New Page".
Full HTML below. This type of example does not work in scripts, but can be tested locally.
<html> <body> <button onclick="clickme()">Click me</button> <script> function clickme() { history.pushState(null, null, "Results/"); document.open("text/html"); document.writeln("New Page"); document.close(); } </script> </body> </html>
Note. Looking for a cross-browser solution, including the latest Chrome 45, which can improve security a bit.
source share