pushstate.html 616 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>popstate event test</title>
  6. </head>
  7. <body>
  8. <script>
  9. (function() {
  10. var test_id;
  11. function showResult(r) {
  12. if(test_id && window.parent.setResult) {
  13. parent.setResult(test_id, r);
  14. } else {
  15. alert(r);
  16. }
  17. }
  18. if(location.hash.length) {
  19. test_id = location.hash.substr(1);
  20. }
  21. if(history.pushState) {
  22. var rand = Math.random();
  23. setTimeout(function() {
  24. history.pushState({foo: 'bar'}, "title", './' + rand);
  25. var result = (location.href.indexOf(rand) > -1);
  26. showResult(result);
  27. }, 100);
  28. }
  29. })();
  30. </script>
  31. </body>
  32. </html>