mirror of
https://github.com/chinchang/web-maker.git
synced 2025-05-24 19:21:45 +02:00
16 lines
477 B
JavaScript
16 lines
477 B
JavaScript
window.addEventListener('message', e => {
|
|
// Web app
|
|
if (e.data && e.data.contents && e.data.contents.match(/<html/)) {
|
|
const frame = document.querySelector('iframe');
|
|
frame.src = frame.src;
|
|
setTimeout(() => {
|
|
frame.contentDocument.open();
|
|
frame.contentDocument.write(e.data.contents);
|
|
frame.contentDocument.close();
|
|
}, 10);
|
|
} else if (e.data && e.data.match(/preview\.html/)) {
|
|
// Chrome extension
|
|
document.querySelector('iframe').src = e.data;
|
|
}
|
|
});
|