fix: window.open
This commit is contained in:
parent
94305ff964
commit
6dd2f37e2e
2 changed files with 16 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
|
||||
import { loadMscore, WebMscore } from './mscore'
|
||||
import { useTimeout } from './utils'
|
||||
import { useTimeout, windowOpen } from './utils'
|
||||
import i18n from './i18n'
|
||||
// @ts-ignore
|
||||
import btnListCss from './btn.css'
|
||||
|
@ -128,7 +128,7 @@ export class BtnList {
|
|||
|
||||
case BtnListMode.ExtWindow: {
|
||||
const div = this._commit()
|
||||
const w = window.open('', undefined, 'resizable,width=230,height=270')
|
||||
const w = windowOpen('', undefined, 'resizable,width=230,height=270')
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
w?.document.body.append(div)
|
||||
window.addEventListener('unload', () => w?.close())
|
||||
|
@ -156,7 +156,7 @@ export namespace BtnAction {
|
|||
|
||||
export const openUrl = (url: UrlInput): BtnAction => {
|
||||
return process(async (): Promise<any> => {
|
||||
window.open(await normalizeUrlInput(url))
|
||||
windowOpen(await normalizeUrlInput(url))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ export namespace BtnAction {
|
|||
btn.onclick = null
|
||||
setText(i18n('PROCESSING')())
|
||||
|
||||
const w = window.open('') as Window
|
||||
const w = windowOpen('') as Window
|
||||
const txt = document.createTextNode(i18n('PROCESSING')())
|
||||
w.document.body.append(txt)
|
||||
|
||||
|
|
12
src/utils.ts
12
src/utils.ts
|
@ -32,6 +32,18 @@ export const useTimeout = async <T> (promise: T | Promise<T>, ms: number): Promi
|
|||
})
|
||||
}
|
||||
|
||||
export const getSandboxWindow = (): Window => {
|
||||
const iframe = document.createElement('iframe')
|
||||
iframe.style.display = 'none'
|
||||
document.body.append(iframe)
|
||||
const w = iframe.contentWindow
|
||||
return w as Window
|
||||
}
|
||||
|
||||
export const windowOpen: Window['open'] = (...args): Window | null => {
|
||||
return getSandboxWindow().open(...args)
|
||||
}
|
||||
|
||||
export const waitForDocumentLoaded = (): Promise<void> => {
|
||||
if (document.readyState !== 'complete') {
|
||||
return new Promise(resolve => {
|
||||
|
|
Loading…
Reference in a new issue