1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-05-24 19:21:45 +02:00
php-web-maker/app/detached-window.js
2019-02-12 15:33:47 +05:30

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;
}
});