Last active
December 17, 2019 07:55
-
-
Save latel/5346026c965098c5df1780fe847cdd55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const waitForJSBridge = new Promise((resolve, reject) => { | |
if (typeof window.StockJSBridge === 'undefined') { | |
let initTimer; | |
let _resolve = () => { | |
window.clearTimeout(initTimer); | |
resolve(); | |
}; | |
initTimer = window.setTimeout(() => { | |
reject(); | |
}, 6000); | |
if (document.addEventListener) { | |
document.addEventListener('StockJSBridgeReady', _resolve, false); | |
} else if (document.attachEvent) { | |
document.attachEvent('StockJSBridgeReady', _resolve); | |
document.attachEvent('onStockJSBridgeReady', _resolve); | |
} | |
} else { | |
// 安卓开发反馈客户端注入的时间可能比js执行的早 | |
// 或者sdk在调用之前已经初始化好了 | |
resolve(); | |
} | |
}); | |
const sdk = { | |
async closeWindow() { | |
await waitForJSBridge; | |
window.StockJSBridge.invoke('exit', {}); | |
} | |
} | |
sdk.closeWindow(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment