This commit is contained in:
Eden Kirin
2025-06-30 16:44:27 +02:00
commit ba93e826f2
2 changed files with 137 additions and 0 deletions

82
child.html Normal file
View File

@ -0,0 +1,82 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Child document</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<style>
body {
background-color: lightskyblue;
}
</style>
</head>
<body class="p-3">
<h1>Hello world from child iframe</h1>
<p>
<a href="https://www.example.com" class="parent-link">Click here</a> to visit an external site.
</p>
<p>Bacon ipsum dolor amet chislic short loin ham, chicken tail brisket meatloaf. Tongue short ribs ball tip short loin
spare ribs fatback pork beef. Turkey tail chuck ball tip shankle turducken tongue landjaeger alcatra salami cupim.
Tongue doner swine meatball. Turducken buffalo pig picanha porchetta corned beef.</p>
<p>Rump fatback strip steak bresaola. Prosciutto andouille jowl venison, strip steak picanha cupim leberkas beef ribs
corned beef capicola boudin ribeye turducken. Shoulder t-bone leberkas, ribeye boudin pastrami turducken. Jowl short
loin ball tip shoulder capicola shankle. Frankfurter cupim prosciutto, jowl pork chop salami picanha pancetta beef chuck
strip steak shoulder short loin pastrami.</p>
<p>Spare ribs turducken pork chop kevin picanha ham ground round biltong. Chuck andouille chicken, tenderloin tri-tip ham
hock ball tip meatball shank cow tongue brisket biltong venison. Jowl picanha pork loin, swine corned beef porchetta
short ribs jerky. Chislic pancetta rump tongue pork belly brisket jowl beef ribs chuck alcatra porchetta bresaola.
Pancetta chuck hamburger ribeye kielbasa fatback filet mignon pork chop spare ribs, swine venison shank. Burgdoggen pork
belly tenderloin salami short loin short ribs t-bone turducken buffalo. Pastrami frankfurter kielbasa pork chop alcatra
sausage turkey burgdoggen bresaola picanha.</p>
<p>Jerky cow pork belly porchetta, cupim chislic pork loin turducken spare ribs. Shankle turkey boudin turducken tongue
short loin. Beef shoulder burgdoggen prosciutto tail chislic boudin swine strip steak sausage meatloaf frankfurter
buffalo landjaeger. Capicola swine fatback meatball ham doner pork belly kevin prosciutto beef ribs rump tail andouille
sirloin corned beef. Cow pig alcatra, tenderloin jerky biltong buffalo chicken frankfurter boudin meatball andouille
tail leberkas venison.</p>
<p>Turducken fatback landjaeger kevin hamburger pork belly. Chicken porchetta shank kielbasa, rump flank pork chop. Pork
strip steak turducken tail brisket tongue. Boudin jerky bacon biltong ball tip tail strip steak fatback meatball chuck
turkey. Brisket meatball ham hock, bacon turducken beef leberkas. Pork chop pastrami turducken, ribeye pancetta alcatra
short ribs t-bone chislic bresaola chuck flank ground round. Hamburger salami bresaola biltong bacon cow, fatback pancetta.</p>
</body>
<script>
function sendHeight() {
const height = document.body.scrollHeight + 0; // add a little extra space
window.parent.postMessage({
cmd: "setHeight",
iframeHeight: height,
}, '*'); // ideally replace * with specific origin
}
function openParentLink(url) {
window.parent.postMessage({
cmd: "openUrl",
url,
}, '*'); // ideally replace * with specific origin
}
window.addEventListener("load", function () {
console.log("Everything loaded, including images and styles");
sendHeight();
});
window.addEventListener('resize', sendHeight);
document.querySelector(".parent-link").addEventListener("click", function (event) {
event.preventDefault();
openParentLink(this.getAttribute("href"));
});
</script>
</html>

55
index.html Normal file
View File

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parent document</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<style>
body {
background-color: whitesmoke;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Hello world</h1>
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<h4 class="text-end">Left</h4>
</div>
<div class="col-md-6">
<iframe src="child.html" id="child-container" height="200px" class="w-100"></iframe>
</div>
<div class="col-md-3">
<h4>Right</h4>
</div>
</div>
</div>
</body>
<script>
window.addEventListener("message", function (event) {
switch (event.data.cmd) {
case "setHeight":
// optionally check event.origin for security
document.getElementById("child-container").style.height = event.data.iframeHeight + "px";
break;
case "openUrl":
// optionally check event.origin for security
window.location.href = event.data.url;
break;
default:
console.warn("Unknown command received:", event.data.cmd);
}
});
window.addEventListener("load", function () {
});
</script>
</html>