iframe postMessage tests
by s_light
HTML
<button onclick="ping();">
Ping
</button>
<div>
<h2>
Log entries:
</h2>
<ul id="log">
</ul>
</div>
CSS
body {
background-color:black;
color:orange;
}
JavaScript
function ping() {
window.top.postMessage('PING');
add_log('send ping to top level window...');
}
window.addEventListener ("message", (event) => {
console.log('jsfiddle', event);
});
function add_log(message) {
const log = document.querySelector('#log');
const el = document.createElement('li');
const now = new Date();
el.innerText = `${now.toISOString()} - ${message}`;
log.append(el);
console.log(message);
}