For writers

Drive an embed from your page

An embed can talk to the page it sits in. Your scripts tell it to do things, and it tells them what happened.

Most writing needs none of this. A course platform that reacts to what a reader did needs all of it.

What your page can tell it

  • Set Code and Get Code. Put a program into the editor, or read back what the reader has now.
  • Execute and Stop Execution. Run it, or stop a run that is not going anywhere.
  • Set Language and Set Version. Change what it runs, and read the lists of what is available.
  • Set STDIN and Set Input Arguments. Give the program what it reads, from your own page.
  • Clear Code Editor and Clear Output. Reset it between steps.

What it tells your page

  • The code changed. You are given the program whenever the reader edits it.
  • The program ran. You are given the output when a run finishes.
  • It is ready. The embed says when it is listening, which is what you wait for before sending anything.

That last one matters more than it looks. Sending an instruction before the embed is ready is the usual reason a page appears to ignore it.

What this makes possible

  • A course that follows along

    Load each step's code as the reader reaches it, and clear the output between steps.

    Good for a lesson where the code changes as the material does.

  • Checking their work

    Read the output when they run something, and respond in your own page.

    Good for exercises with a right answer, and progress you want to record.

What next

If you want to run code inside your own product rather than inside a page you wrote, that is the API rather than an embed.

Drive an embed from your page has the full method and event reference.

This website uses cookies to ensure you get the best experience on our website.