first commit, basic embed + message passing
This commit is contained in:
commit
1fa71c7474
44
index.html
Normal file
44
index.html
Normal file
|
@ -0,0 +1,44 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<iframe id="padembed" width="640" height="360" name="iframename" src="https://pad.ma/AGR/editor/00:04:55.800,00:00:21.880,00:04:55.800#embed" frameborder="0" allowfullscreen></iframe>
|
||||
<script>
|
||||
console.log('hello');
|
||||
const $iframe = document.getElementById('padembed');
|
||||
|
||||
|
||||
window.addEventListener('message', listener, false);
|
||||
|
||||
function listener(event) {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === 'init') document.getElementById(data.target).isInit = true;
|
||||
console.log('received event', event);
|
||||
console.log('name', event.data.name);
|
||||
}
|
||||
|
||||
$iframe.addEventListener('load', () => {
|
||||
console.log('iframe loaded');
|
||||
let timeout;
|
||||
function init() {
|
||||
console.log('init called');
|
||||
if ($iframe.isInit) {
|
||||
clearTimeout(timeout);
|
||||
return;
|
||||
}
|
||||
$iframe.contentWindow.postMessage(JSON.stringify({
|
||||
data: {
|
||||
oxid: 'padembed'
|
||||
},
|
||||
event: 'init'
|
||||
}), '*');
|
||||
timeout = setTimeout(init, 250);
|
||||
}
|
||||
init();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user