Control the wheel with JavaScript
The copied code works on its own. If you write your own page code, you can also start spins, change entries and read each winner through window messages, without loosening the frame's sandbox.
Start a spin and read the winner
Add <button id="spin-from-page" type="button" disabled>Spin</button> to your page, and put this script after the embed code. The wheel ignores commands until it sends ready, so the button stays disabled until then.
const frame = document.querySelector('iframe[src^="https://choicespin.com/e"]');
const spinButton = document.querySelector("#spin-from-page");
// Every message carries the same channel and version.
function send(action, extra = {}) {
frame.contentWindow.postMessage(
{ channel: "choicespin.embed", version: 1, action, ...extra },
"*"
);
}
window.addEventListener("message", (event) => {
if (event.source !== frame.contentWindow || event.origin !== "null") return;
const data = event.data;
if (data?.channel !== "choicespin.embed" || data?.version !== 1) return;
if (data.event === "ready") spinButton.disabled = false;
if (data.event === "spin-end") console.log("Winner:", data.winner);
});
spinButton.addEventListener("click", () => send("spin"));
Actions you can send
spin starts a spin
setEntries replaces the entries with an entries array of 2 to 100 strings
addEntry adds one entry string
removeWinner removes the latest winner
reset brings back the entries from the code
Events you receive
ready, spin-start, spin-end with winner and index, entries-changed and error. Each one also reports the current entry count.
Three rules to know
Send messages with "*" as the target, because a sandboxed frame has no origin you could name. The message still goes only to that one frame. When a message comes back, its origin reads "null", so trust it only when event.source is also the frame's window. The wheel listens only to the page that embeds it and answers a malformed command with an error event. Keep the generated sandbox and referrerpolicy attributes as they are: the wheel learns which page embeds it from the referrer, so a no-referrer policy switches messaging off.