diff --git a/src/components/IframeDrawer.vue b/src/components/IframeDrawer.vue index 0eafaf55..6b5fb189 100644 --- a/src/components/IframeDrawer.vue +++ b/src/components/IframeDrawer.vue @@ -26,9 +26,10 @@ const inIframe = computed((): boolean => { }) useEventListener(window, 'popstate', updateIframeUrl) -// nextTick(() => { -// useEventListener(iframeRef.value?.contentWindow, 'pushstate', updateCurrentUrl) -// }) +nextTick(() => { + useEventListener(iframeRef.value?.contentWindow, 'historyChange', updateCurrentUrl) + useEventListener(iframeRef.value?.contentWindow, 'popstate', updateCurrentUrl) +}) onMounted(async () => { history.pushState(null, '', props.url) @@ -46,17 +47,17 @@ onUnmounted(() => { history.replaceState(null, '', 'https://www.bilibili.com') }) -// function updateCurrentUrl() { -// if (iframeRef.value?.contentWindow) { -// try { -// currentUrl.value = iframeRef.value.contentWindow.location.href.replace(/\/$/, '') -// history.pushState(null, '', currentUrl.value.replace(/\/$/, '')) -// } -// catch (error) { -// console.error('Unable to access iframe URL:', error) -// } -// } -// } +function updateCurrentUrl() { + if (iframeRef.value?.contentWindow) { + try { + currentUrl.value = iframeRef.value.contentWindow.location.href.replace(/\/$/, '') + history.pushState(null, '', currentUrl.value.replace(/\/$/, '')) + } + catch (error) { + console.error('Unable to access iframe URL:', error) + } + } +} async function updateIframeUrl() { if (isHomePage()) { @@ -98,7 +99,6 @@ async function releaseIframeResources() { } function handleOpenInNewTab() { - // window.open(props.url, '_blank') if (iframeRef.value) window.open(iframeRef.value.contentWindow?.location.href.replace(/\/$/, ''), '_blank') } @@ -236,7 +236,7 @@ watchEffect(() => { >