From 26253ebf8f4d828fdeecb887337905e13c8a589a Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Mon, 8 Sep 2025 12:37:18 +0400 Subject: [PATCH] Viewer iframe location is checked every 0.1s The only way to detect change of the iframe location performed via `History.pushState()` or `History.replaceState()` is to constantly monitor it, since those methods don't trigger any events. --- static/skin/viewer.js | 11 ++++++++--- test/server.cpp | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/static/skin/viewer.js b/static/skin/viewer.js index 564971fe..c683158c 100644 --- a/static/skin/viewer.js +++ b/static/skin/viewer.js @@ -267,8 +267,15 @@ function translateErrorPageIfNeeded() { translatePageInWindow(contentIframe.contentWindow); } + +let iframeLocationHref = null; + function handle_content_url_change() { + if ( iframeLocationHref == contentIframe.contentWindow.location.href ) + return; + const iframeLocation = contentIframe.contentWindow.location; + iframeLocationHref = iframeLocation.href; console.log('handle_content_url_change: ' + iframeLocation.href); document.title = contentIframe.contentDocument.title; const iframeContentUrl = iframeLocation.pathname + iframeLocation.hash; @@ -432,9 +439,7 @@ function on_content_load() { contentIframe.classList.remove("hidden"); loader.style.display = "none"; contentIframe.contentWindow.onhashchange = handle_content_url_change; - if ( viewerSetupComplete ) { - handle_content_url_change(); - } + setInterval(handle_content_url_change, 100); setup_chaperon_mode(); } diff --git a/test/server.cpp b/test/server.cpp index 90112729..40a4f73e 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -77,7 +77,7 @@ const ResourceCollection resources200Compressible{ { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/taskbar.css" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/taskbar.css?cacheid=42e90cb9" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/viewer.js" }, - { STATIC_CONTENT, "/ROOT%23%3F/skin/viewer.js?cacheid=580d9826" }, + { STATIC_CONTENT, "/ROOT%23%3F/skin/viewer.js?cacheid=3208c3ed" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/fonts/Poppins.ttf" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/fonts/Poppins.ttf?cacheid=af705837" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/fonts/Roboto.ttf" }, @@ -338,7 +338,7 @@ R"EXPECTEDRESULT( - + const blankPageUrl = root + "/skin/blank.html?cacheid=6b1fa032";