update iframe demo

This commit is contained in:
Harvey Zack committed 2022-09-21 23:18:19 +08:00
1 parent 8b8d58dd66
commit 2d48f247ad
4 files changed
+245 -233

No files matched your search

+11 -11
View File
@@ -40,29 +40,29 @@
<body>
<div class="container">
<iframe id="iframe" src="./iframe.inner.html" frameborder="0" width="100%" height="100%"></iframe>
<iframe id="iframe" src="./iframe.inner.html" frameborder="0" width="100%" height="100%"
allowfullscreen="true"></iframe>
</div>
<script>
const $iframe = document.getElementById('iframe');
window.addEventListener('message', event => {
console.log('来自子窗口的信息 -->', event.data);
const { type, data } = event.data;
switch (type) {
case 'fullscreenWeb':
if (data) {
$iframe.classList.add('fullscreenWeb');
const { clientWidth, clientHeight } = document.documentElement;
$iframe.contentWindow.postMessage({
type: 'autoOrientation',
data: {
clientWidth,
clientHeight
},
}, '*');
} else {
$iframe.classList.remove('fullscreenWeb');
}
// 向子窗口发送信息
$iframe.contentWindow.postMessage({
from: 'parent',
type: 'fullscreenWeb',
data: data,
}, '*');
break;
default:
break;