1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-06-26 09:42:39 +02:00

change preview method to postmessage

This commit is contained in:
Kushagra Gour
2024-03-22 02:57:23 +05:30
parent 4ee7a2a2c0
commit c7e523c374
3 changed files with 59 additions and 6 deletions

View File

@ -0,0 +1,20 @@
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.contentDocument.open();
frame.contentDocument.write(e.data.contents);
frame.contentDocument.close();
}, 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.postMessage(e.data, '*');
}
});