fix(iframe-drawer): correct URL location when opening in a new tab (#1068)

This commit is contained in:
Hakadao
2024-10-27 03:05:58 +08:00
parent 0044bac3fd
commit fbde884004
2 changed files with 34 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { useThrottleFn, useToggle } from '@vueuse/core'
import { useEventListener, useThrottleFn, useToggle } from '@vueuse/core'
import type { Ref } from 'vue'
import type { BewlyAppProvider } from '~/composables/useAppProvider'
@@ -181,6 +181,21 @@ async function haveScrollbar() {
return scrollHeight > window.innerHeight
}
// When opening a video in drawer mode, listen for changes to the drawer's inner iframe url.
// When the iframe's url changes, update the parent url to match the iframe's url.
const beforeUrl = ref<string>(location.href.replace(/\/$/, ''))
if (inIframe.value) {
useEventListener(window, 'pushstate', handleIframeUrlChange)
useEventListener(window, 'click', handleIframeUrlChange)
function handleIframeUrlChange() {
if (beforeUrl.value.replace(/\/$/, '') !== parent.location.href.replace(/\/$/, '')) {
parent.history.pushState(null, '', location.href.replace(/\/$/, ''))
}
beforeUrl.value = location.href.replace(/\/$/, '')
}
}
provide<BewlyAppProvider>('BEWLY_APP', {
activatedPage,
mainAppRef,