Spaces:
Paused
Paused
File size: 905 Bytes
3c3f089 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
export const createIframeContent = (css: string, html: string) => {
return `
<html lang="en">
<head>
<title>Codetree </title>
<style>
${css}
</style>
</head>
<body>
<div id="root">
${html}
</div>
<script>
//====== send massage to iframe
window.onerror = function (err) {
window.parent.postMessage(
{ source: "iframe", type: "iframe_error", message: err },
"*"
);
};
window.onunhandledrejection = function (err) {
window.parent.postMessage(
{ source: "iframe", type: "iframe_error", message: err.reason },
"*"
);
};
//====== listen to income message of parent
window.onmessage = function (event) {
try {
eval(event.data);
} catch (error) {
throw error;
}
};
</script>
</body>
</html>
`;
};
|