mirror of
https://github.com/kevinveenbirkenbach/homepage.veen.world.git
synced 2025-07-19 15:44:24 +02:00
Added iframe observer
This commit is contained in:
parent
b0446dcd29
commit
ab8ea0dbd6
@ -52,6 +52,7 @@ function openIframe(url) {
|
|||||||
.attr('src', url)
|
.attr('src', url)
|
||||||
.fadeIn(1500, function() {
|
.fadeIn(1500, function() {
|
||||||
syncIframeHeight();
|
syncIframeHeight();
|
||||||
|
observeIframeNavigation();
|
||||||
});
|
});
|
||||||
|
|
||||||
// URL-State pushen
|
// URL-State pushen
|
||||||
@ -156,3 +157,27 @@ window.openIframeInNewTab = openIframeInNewTab;
|
|||||||
|
|
||||||
// Adjust iframe height on window resize
|
// Adjust iframe height on window resize
|
||||||
window.addEventListener('resize', syncIframeHeight);
|
window.addEventListener('resize', syncIframeHeight);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Observe iframe location changes (Same-Origin only).
|
||||||
|
*/
|
||||||
|
function observeIframeNavigation() {
|
||||||
|
const iframe = mainElement.querySelector("iframe");
|
||||||
|
if (!iframe || !iframe.contentWindow) return;
|
||||||
|
|
||||||
|
let lastUrl = iframe.contentWindow.location.href;
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
try {
|
||||||
|
const currentUrl = iframe.contentWindow.location.href;
|
||||||
|
if (currentUrl !== lastUrl) {
|
||||||
|
lastUrl = currentUrl;
|
||||||
|
const newUrl = new URL(window.location);
|
||||||
|
newUrl.searchParams.set('iframe', currentUrl);
|
||||||
|
window.history.replaceState({}, '', newUrl);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Cross-origin – ignore
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user