Using iframe message passing. Your page can recieve "glif ran" events from our embeddable player.
Here is the demo:
way you can receive results from the embed player. For security reasons, you can only listen to the demo and can't send to it. If you want to run glifs, register a key and . Additionally, check out + for writing more advanced examples.
Simple example
You can copy a glif embed code from the glif page in the "share" menu top right.
Here's a working webpage that runs one of my personal favorite glifs, by .
Here is the core iframe communication part. Your page recieves events from the glif iframe using postMessage API
<!doctype html>
<script>
window.addEventListener("message", handleMessage, false);
function handleMessage(event) {
const allowedDomains = ["https://glif.app"];
if (!allowedDomains.includes(event.origin)) {
console.warn("ignoring message from untrusted origin");
return;
}
const message = event.data;
if (message.type === "glifRunStarted") {
// handle a glif run starting (e.g. show a loading indicator)
} else if (message.type === "glifRunCompleted") {
// handle a glif run completing (e.g. show the final image)
} else {
// currently only sends those 2 messages so nothing else here yet!
}
}
</script>