1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-01-18 04:48:50 +01:00

detached-window: recieve calls only from webmaker window. fixes #363

This commit is contained in:
Kushagra Gour 2019-02-12 15:10:29 +05:30
parent 1edb2e5c5a
commit 136c3b4741

View File

@ -1,5 +1,6 @@
window.addEventListener('message', e => {
if (e.data && e.data.contents) {
// Web app
if (e.data && e.data.contents && e.data.contents.match(/<html/)) {
const frame = document.querySelector('iframe');
frame.src = frame.src;
setTimeout(() => {
@ -7,7 +8,8 @@ window.addEventListener('message', e => {
frame.contentDocument.write(e.data.contents);
frame.contentDocument.close();
}, 10);
} else {
} else if (e.data && e.data.match(/preview\.html/)) {
// Chrome extension
document.querySelector('iframe').src = e.data;
}
});