mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-26 00:11:13 +02:00
19 lines
548 B
JavaScript
19 lines
548 B
JavaScript
window.addEventListener('message', e => {
|
|
// Recieving from app window
|
|
if (e.data && e.data.contents && e.data.contents.match(/<html/)) {
|
|
const frame = document.querySelector('iframe');
|
|
frame.src = frame.src;
|
|
setTimeout(() => {
|
|
frame.contentWindow.postMessage(e.data, '*');
|
|
}, 10);
|
|
}
|
|
if (e.data && e.data.url && e.data.url.match(/index\.html/)) {
|
|
document.querySelector('iframe').src = e.data.url;
|
|
}
|
|
|
|
// Recieving from preview iframe
|
|
if (e.data && e.data.logs) {
|
|
(window.opener || window.top).postMessage(e.data, '*');
|
|
}
|
|
});
|