history state (due to pushState) issues
Posted: Wed Jan 27, 2021 2:41 pm
Hi,
I've been struggling to debug a strange behavior that the plugin exhibits.
How to reproduce on this forum:
1. Scroll in the forum list to the bottom
2. click the last forum (e.g., Apache and Server related)
3. Press back on the browser - it jumps to the correct location, but to the top of the page and note that the URL remains the same as the previous page (not the list of forums).
4. Press back on the browser again - NOW it jumps both to the correct location on the page and the correct URL.
I've been able to track down what I think is the root cause. It looks like when you click, the code in the phpbb overall_footer will notice that it is an internal call and convert the A-click into a message to the parent of the IFRAME.
$(document).on("click", "a", function(e) {
......
if ('parentIFrame' in window){
if( typeof w3allNOappend == 'undefined' || w3allNOappend == false ){
window.parentIFrame.sendMessage(w3allappend);
}
}
The message of the IFRAME does the pushState with the correct URL. However, there are now two events in the system - pushState with the correct state and the original A-click (seen above) which doesn't preventDefault.
I tried a few things, but no luck. I tried replaceState so that the state would override the A click's state, but that doesn't work (I think because theres' not always a state to replace). I also tried to preventDefault on the A tags' click event. No luck. The only thing that works is to change the location of the root of the iframe - but that's really inefficient as it loads everything from the beginning.
ideas or suggestions?
I've been struggling to debug a strange behavior that the plugin exhibits.
How to reproduce on this forum:
1. Scroll in the forum list to the bottom
2. click the last forum (e.g., Apache and Server related)
3. Press back on the browser - it jumps to the correct location, but to the top of the page and note that the URL remains the same as the previous page (not the list of forums).
4. Press back on the browser again - NOW it jumps both to the correct location on the page and the correct URL.
I've been able to track down what I think is the root cause. It looks like when you click, the code in the phpbb overall_footer will notice that it is an internal call and convert the A-click into a message to the parent of the IFRAME.
$(document).on("click", "a", function(e) {
......
if ('parentIFrame' in window){
if( typeof w3allNOappend == 'undefined' || w3allNOappend == false ){
window.parentIFrame.sendMessage(w3allappend);
}
}
The message of the IFRAME does the pushState with the correct URL. However, there are now two events in the system - pushState with the correct state and the original A-click (seen above) which doesn't preventDefault.
I tried a few things, but no luck. I tried replaceState so that the state would override the A click's state, but that doesn't work (I think because theres' not always a state to replace). I also tried to preventDefault on the A tags' click event. No luck. The only thing that works is to change the location of the root of the iframe - but that's really inefficient as it loads everything from the beginning.
ideas or suggestions?