mirror of
https://github.com/chinchang/web-maker.git
synced 2025-08-06 13:26:36 +02:00
change preview method to postmessage
This commit is contained in:
20
preview/detached-window.js
Normal file
20
preview/detached-window.js
Normal 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, '*');
|
||||
}
|
||||
});
|
22
preview/preview.html
Normal file
22
preview/preview.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
#demo-frame {
|
||||
border: 0;
|
||||
width: 100%;
|
||||
background: white;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body>
|
||||
<iframe
|
||||
src="about://blank"
|
||||
frameborder="0"
|
||||
id="demo-frame"
|
||||
allowfullscreen
|
||||
></iframe>
|
||||
|
||||
<script src="detached-window.js"></script>
|
||||
</body>
|
Reference in New Issue
Block a user