chrome.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <html>
  2. <head>
  3. <title>Chrome History API Data Artifact</title>
  4. </head>
  5. <body>
  6. <p>This demo demonstrates an issue with Google Chrome versions 8-10 (possibly 11) where if you push a state with data, then do history.back to the initial state, the event.state will contain the pushed states data instead of being null.</p>
  7. <p>Note: The issue requires a clean history list, as such this should always be opened in a new tab/window where there are no prior history items.</p>
  8. <p>Reported by <a href="http://balupton.com">Benjamin Lupton</a> author of <a href="http://github.com/balupton/history.js">History.js</a></p>
  9. <button id="bug">bug</button>
  10. <button id="reset">reset</button>
  11. <textarea id="log" style="width:100%;height:200px;margin-top:1em;"></textarea>
  12. <script type="text/javascript">
  13. (function(){
  14. window.onpopstate = function(event) {
  15. var message = ("onpopstate: location: " + document.location.href + ", data: " + JSON.stringify(event.state));
  16. document.getElementById('log').innerHTML += message+"\n\n";
  17. };
  18. document.getElementById('bug').onclick = function(){
  19. setTimeout(function(){
  20. history.pushState({state:'new'},'New State','?new');
  21. },1e3);
  22. setTimeout(function(){
  23. history.back();
  24. },2e3);
  25. };
  26. document.getElementById('reset').onclick = function(){
  27. document.location.href = document.location.href.replace(/[\#\?].*/,"");
  28. };
  29. })();
  30. </script>
  31. </body>
  32. </html>