<!DOCTYPE html>
<style>
iframe {
position:absolute;
top: 0px;
left: 0px;
width: 160px;
height: 100px;
overflow-y: scroll;
}
</style>
<iframe src="http://127.0.0.1:8080/intersection-observer/resources/nested-cross-origin-subframe.html"></iframe>
<script>
var iframe = document.querySelector("iframe");
var port;
var iframe_loaded = false;
var start_message_queued = false;
// This frame forwards messages bidirectionally between its parent frame and
// its child frame. The initiating message comes from the parent, but it
// needs to be held if the child frame is not yet finished loading. The
// booleans above account for the different possible orderings of events.
function handleMessage(event) {
if (event.source == iframe.contentWindow) {
port.postMessage(event.data, "*");
} else if (iframe_loaded){
port = event.source;
iframe.contentWindow.postMessage(event.data, "*");
} else {
port = event.source;
start_message_queued = true;
}
}
window.addEventListener("message", handleMessage);
iframe.onload = function () {
iframe_loaded = true;
if (start_message_queued) {
iframe.contentWindow.postMessage("", "*");
start_message_queued = false;
}
}
</script>