Advertisement
DigitalMag

popstate

Sep 23rd, 2019
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <script>
  5.            
  6.             var stack = [];
  7.             window.onpopstate = function(){ //для ие8-9 будут прямые переходы
  8.  
  9.                 var c = (stack.pop());                                      //JSON.stringify
  10.                 stack.push({'content': document.querySelector('content').innerHTML});
  11.                 document.querySelector('content').innerHTML = c['content'];
  12.                
  13.             }
  14.             function ClickWeb(elem, e){    
  15.  
  16.                 stack.push({'content': document.querySelector('content').innerHTML});                                                               //сохраняем все данные со страницы
  17.                 history.pushState(null, null,'/web');
  18.                 document.querySelector('content').innerHTML = '<a href="/">Web2</a>';
  19.             }
  20.            
  21.         </script>
  22.         <style>
  23.  
  24.         </style><!--@import url(style.css);-->
  25.         <meta>
  26.             <title> </title>
  27.         </meta>
  28.    
  29.     </head>
  30.     <body>
  31.    
  32.         <content>
  33.         <header>
  34.             <h1 id=header>This is index page</h1>
  35.         </header>
  36.         <p>
  37.             Welcome to <a href="/web">Web1</a> with refresh
  38.         </p>
  39.         <p>
  40.             Welcome to <b href="/web" onclick='ClickWeb(this, event);' style='cursor: pointer;color:red;'>Web1</b> without refresh
  41.         </p>
  42.         </content>
  43.     </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement