|
310 | 310 | //toggled internally when location.hash is updated to match the url of a successful page load |
311 | 311 | ignoreNextHashChange: false, |
312 | 312 |
|
313 | | - ignoreNextPopState: false |
| 313 | + //start with popstate disabled |
| 314 | + ignoreNextPopState: true |
314 | 315 | }, |
315 | 316 |
|
316 | 317 | //define first selector to receive focus when a page is shown |
|
1122 | 1123 | $.mobile.changePage( href, { transition: transition, reverse: reverse, role: role } ); |
1123 | 1124 | event.preventDefault(); |
1124 | 1125 | }); |
| 1126 | + |
| 1127 | + |
| 1128 | + // Popstate is disabled until after window onload |
| 1129 | + // This is to avoid the initial popstate call that occurs in Chrome at load |
| 1130 | + $window.bind( "load", function(){ |
| 1131 | + setTimeout(function(){ |
| 1132 | + urlHistory.ignoreNextPopState = false; |
| 1133 | + }, 0 ); |
| 1134 | + }); |
1125 | 1135 |
|
1126 | | - //hashchange event handler |
| 1136 | + //hashchange and popstate event handler |
1127 | 1137 | $window.bind( "hashchange popstate", function( e, triggered ) { |
1128 | 1138 | //find first page via hash |
1129 | 1139 | var to = path.get(), |
|
1134 | 1144 | pushStateSupported = $.support.pushState, |
1135 | 1145 | currHref = location.href.split("#")[0]; |
1136 | 1146 |
|
| 1147 | + //popstate is disabled until a delay after onload, due to chrome firing it on every page load |
| 1148 | + if( e.type == "popstate" && urlHistory.ignoreNextPopState ){ |
| 1149 | + return; |
| 1150 | + } |
| 1151 | + |
| 1152 | + //replace the hashchange if pushstate is supported! |
1137 | 1153 | if( e.type === "hashchange" && pushStateSupported && !isDialog ){ |
1138 | 1154 | if( isGeneratedPage ){ |
1139 | 1155 | var splitter = '&' + $.mobile.subPageUrlKey; |
|
1144 | 1160 |
|
1145 | 1161 | //if it worked, return here. |
1146 | 1162 | if( location.href.split("#")[0] !== currHref ){ |
1147 | | - return; |
| 1163 | + // return; |
1148 | 1164 | } |
1149 | 1165 | } |
1150 | 1166 |
|
1151 | | - |
1152 | | - |
1153 | 1167 | //if listening is disabled (either globally or temporarily), or it's a dialog hash |
1154 | | - // seems this ignored hashchange stuff is unnecessary with pushstate in play |
1155 | | - if( e.type === "hashchange" && !pushStateSupported && ( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) ) { |
| 1168 | + if( e.type === "hashchange" && ( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) ) { |
1156 | 1169 | urlHistory.ignoreNextHashChange = false; |
1157 | 1170 | return; |
1158 | 1171 | } |
| 1172 | + |
| 1173 | + |
| 1174 | + |
1159 | 1175 |
|
1160 | 1176 | //if it's a generated subpage, like a nested list, only use the |
1161 | 1177 |
|
|
0 commit comments