DarkDaskin

nav.html

Oct 18th, 2013
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Y U NO WORK?</title>
  5.     <style>
  6.         body {
  7.             width: 100%;
  8.             height: 100%;
  9.             margin: 0;
  10.         }
  11.         #menu {
  12.             width: 100%;
  13.             height: 30px;
  14.             background: yellow;
  15.             font-size: 20px;
  16.             padding: 10px;
  17.         }
  18.         .active {
  19.             font-size: 24px;
  20.             font-weight: bold;
  21.         }
  22.         #frame {
  23.             width: 100%;
  24.             height: 100%;
  25.             min-height: 500px;
  26.             margin-top: 50px;
  27.             border: none;
  28.         }
  29.     </style>
  30.     <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  31.     <script type="text/javascript">
  32.         $(function () {
  33.             $('#menu a').click(function() {
  34.                 var link = this;
  35.                 selectLink(link);
  36.                
  37.                 $('#frame').one('load', function() {
  38.                     var frameWindow = getFrameWindow();
  39.                     frameWindow.history.replaceState({ linkId: link.id },frameWindow.document.title, frameWindow.location.href);
  40.                    
  41.                     // Does not work
  42.                     $(frameWindow).on('popstate', function () { handleHistory('[email protected]'); });
  43.                 });
  44.                 $('#frame').attr('src', link.href);
  45.                
  46.                 return false;
  47.             });
  48.            
  49.             // The following does not work
  50.             $(window).on('popstate', function () { handleHistory('popstate@window'); });
  51.             $(getFrameWindow()).on('popstate', function () { handleHistory('[email protected]'); });
  52.             $('#frame').on('popstate', function () { handleHistory('popstate@iframe'); });
  53.            
  54.             // This works but too slow
  55.             $('#frame').load(function () { handleHistory('load@iframe'); });
  56.         });
  57.        
  58.         function getFrameWindow() {
  59.             return $('#frame')[0].contentWindow;
  60.         }
  61.        
  62.         function selectLink (link) {
  63.             $('#menu a').removeClass('active');
  64.             $(link).addClass('active');
  65.         }
  66.        
  67.         function handleHistory (caller) {
  68.             console.log('Handling history from ' + caller);
  69.             var state = getFrameWindow().history.state;
  70.             if (state)
  71.                 selectLink('#' + getFrameWindow().history.state.linkId);
  72.         }
  73.     </script>
  74. </head>
  75. <body>
  76.     <div id="menu">
  77.         <a id="1" href="out.aspx?1">1</a>
  78.         <a id="2" href="out.aspx?2">2</a>
  79.         <a id="3" href="out.aspx?3">3</a>
  80.     </div>
  81.     <iframe id="frame"></iframe>
  82. </body>
  83. </html>
Advertisement
Add Comment
Please, Sign In to add comment