diff --git a/docs/assets/example/iframe.js b/docs/assets/example/iframe.js index 4843e6040..c8cbdf1f5 100644 --- a/docs/assets/example/iframe.js +++ b/docs/assets/example/iframe.js @@ -15,6 +15,11 @@ const iframe = new ArtplayerToolIframe({ url: '/iframe.html', }) +window.addEventListener('artplayer:example:cleanup', () => { + iframe.destroy() + $iframe.remove() +}, { once: true }) + iframe.message(({ type, data }) => { switch (type) { case 'fullscreenWeb': @@ -44,4 +49,7 @@ iframe.commit(() => { data: state, }) }) +}).catch((error) => { + if (!iframe.destroyed) + console.error(error) }) diff --git a/docs/assets/js/common.js b/docs/assets/js/common.js index 10e9a5f96..7bfc0e023 100644 --- a/docs/assets/js/common.js +++ b/docs/assets/js/common.js @@ -205,8 +205,9 @@ } function runCode() { + window.dispatchEvent(new Event('artplayer:example:cleanup')) // Destroy all existing instances - Artplayer.instances.forEach((art) => art.destroy(true)) + Artplayer.instances.slice().forEach((art) => art.destroy(true)) const value = editor.getValue() eval(value) diff --git a/docs/index.html b/docs/index.html index bef0fe4a1..9b9b72ba5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -229,12 +229,17 @@
-