| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Adds event listeners and populates on-load-div. | 5 // Adds event listeners and populates on-load-div. |
| 6 window.onload = function() { | 6 window.onload = function() { |
| 7 window.addEventListener('popstate', onPopstate); | 7 window.addEventListener('popstate', onPopstate); |
| 8 window.addEventListener('hashchange', onHashChange); | 8 window.addEventListener('hashchange', onHashChange); |
| 9 updateOnLoadText('OnLoadText'); | 9 updateOnLoadText('OnLoadText'); |
| 10 }; | 10 }; |
| 11 | 11 |
| 12 // Populates pop-state-received-div and state-object-div upon a popstate event. | 12 // Populates pop-state-received-div and state-object-div upon a popstate event. |
| 13 var onPopstate = function(e) { | 13 var onPopstate = function(e) { |
| 14 updatePopStateReceivedText(true); | 14 updatePopStateReceivedText(true); |
| 15 updateStateObjectText(e.state); | 15 var stateText = e.state ? e.state : '(NO STATE OBJECT)'; |
| 16 updateStateObjectText(stateText); |
| 16 }; | 17 }; |
| 17 | 18 |
| 18 // Populates hash-change-received-div upon receiving of a hashchange event. | 19 // Populates hash-change-received-div upon receiving of a hashchange event. |
| 19 var onHashChange = function(e) { | 20 var onHashChange = function(e) { |
| 20 updateHashChangeReceivedText(true); | 21 updateHashChangeReceivedText(true); |
| 21 } | 22 } |
| 22 | 23 |
| 23 var updateOnLoadText = function(text) { | 24 var updateOnLoadText = function(text) { |
| 24 document.getElementById('on-load-div').innerHTML = text; | 25 document.getElementById('on-load-div').innerHTML = text; |
| 25 } | 26 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 var goNoParameter = function() { | 58 var goNoParameter = function() { |
| 58 onButtonTapped(); | 59 onButtonTapped(); |
| 59 window.history.go(); | 60 window.history.go(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 var goZero = function() { | 63 var goZero = function() { |
| 63 onButtonTapped(); | 64 onButtonTapped(); |
| 64 window.history.go(0); | 65 window.history.go(0); |
| 65 } | 66 } |
| 66 | 67 |
| 68 var goBack = function() { |
| 69 onButtonTapped(); |
| 70 window.history.back(); |
| 71 } |
| 72 |
| 73 var goForward = function() { |
| 74 onButtonTapped(); |
| 75 window.history.forward(); |
| 76 } |
| 77 |
| 67 var go2 = function() { | 78 var go2 = function() { |
| 68 onButtonTapped(); | 79 onButtonTapped(); |
| 69 window.history.go(2); | 80 window.history.go(2); |
| 70 } | 81 } |
| 71 | 82 |
| 72 var goBack2 = function() { | 83 var goBack2 = function() { |
| 73 onButtonTapped(); | 84 onButtonTapped(); |
| 74 window.history.go(-2); | 85 window.history.go(-2); |
| 75 } | 86 } |
| 87 |
| 88 var pushStateWithHash = function() { |
| 89 onButtonTapped(); |
| 90 window.history.pushState('STATE_OBJECT', 'Title', '#hash'); |
| 91 } |
| OLD | NEW |