Re: history state (due to pushState) issues
Posted: Tue Feb 02, 2021 11:18 am
The preloader thing is only a preliminary idea. I haven't been able to get to it yet.
About the history state, I was thinking last night about a possible solution, but tried it this morning and it failed. Still not sure why (this is a very convoluted issue).
popState appears to be triggering only on the second "Back" command, which actually holds the scrolling position. I was trying to find another possible event that could trigger instead. I found a couple but they are mostly page lifecycle events triggered by the move.
Then, I was thinking, what if I could change the order so that the popState happens last, so that the popState would trigger on the first BACK, that would let me do the history.back() inside the popState with no additional side effects.
This is the code I tried, however strangely it does not work. The popState event always happens on the second ("Good") back. I tried adding a setTimeout 0 so that the pushState definitely happens after the new URL registers, but I don't think that works.
Documentation also says replaceState should also cause a popState, but in my testing that does not work either.
The only thing I think might do the trick is to clone the iframe, change its source and then connect it to the IframeResizer and then kill the old one...
I'm out of ideas...
About the history state, I was thinking last night about a possible solution, but tried it this morning and it failed. Still not sure why (this is a very convoluted issue).
popState appears to be triggering only on the second "Back" command, which actually holds the scrolling position. I was trying to find another possible event that could trigger instead. I found a couple but they are mostly page lifecycle events triggered by the move.
Then, I was thinking, what if I could change the order so that the popState happens last, so that the popState would trigger on the first BACK, that would let me do the history.back() inside the popState with no additional side effects.
This is the code I tried, however strangely it does not work. The popState event always happens on the second ("Good") back. I tried adding a setTimeout 0 so that the pushState definitely happens after the new URL registers, but I don't think that works.
Code: Select all
iFrameResize({
log : false,
inPageLinks : true,
targetOrigin: '".$w3all_url_to_cms."',
checkOrigin : w3all_orig_domains,
// heightCalculationMethod: 'documentElementOffset', // If iframe not resize correctly, un-comment (or change with one of others available resize methods)
// see: https://github.com/davidjbradshaw/iframe-resizer#heightcalculationmethod
onMessage : function(messageData){ // Callback fn when message is received
// w3all simple js check and redirects
var w3all_passed_url = messageData.message.append.toString();
var w3all_ck = \"".$_SERVER['SERVER_NAME']."\";
var w3all_pass_ext = (w3all_passed_url.indexOf(w3all_ck) > -1);
var w3all_ck_preview = (w3all_passed_url.indexOf('preview') > -1);
if (w3all_ck_preview == false) { // or the phpBB passed preview link, will be recognized as external, and preview will redirect to full forum url instead
// so these are maybe, external iframe redirects
if (w3all_pass_ext == true) {
window.location.replace(w3all_passed_url);
}
if (/^(f|ht)tps?:\/\//i.test(w3all_passed_url)) {
window.location.replace(w3all_passed_url);
}
}
// do not pass to be encoded an url with sid or if it point to phpBB admin ACP via iframe
if( /[^-0-9A-Za-z\._#\:\?\/=&%]/ig.exec(w3all_passed_url) !== null || /adm\//ig.exec(w3all_passed_url) !== null || /sid=/ig.exec(w3all_passed_url) !== null ){
w3all_passed_url = '';
}
// PUSH phpBB URLs //
w3all_passed_url = window.btoa(unescape(encodeURIComponent(w3all_passed_url)));
w3all_passed_url_push = '".$w3allhomeurl."/".$wp_w3all_forum_folder_wp."/?".$w3all_iframe_custom_w3fancyurl."=' + w3all_passed_url;
messageData.iframe.contentWindow.document.location.href= messageData.message.ref;
history.pushState({w3all_passed_url: w3all_passed_url}, \"Forums\", w3all_passed_url_push);
}
});
window.onpopstate = function(event) {
console.log(\"pop state: \" + JSON.stringify(event.state));
};
Code: Select all
if ('parentIFrame' in window){
if( typeof w3allNOappend == 'undefined' || w3allNOappend == false ){
window.parentIFrame.sendMessage({ append:w3allappend, ref: href});
e.preventDefault();
}
}
Documentation also says replaceState should also cause a popState, but in my testing that does not work either.
The only thing I think might do the trick is to clone the iframe, change its source and then connect it to the IframeResizer and then kill the old one...
I'm out of ideas...