Try It Editor
Tip: Press Ctrl/⌘ + Enter to Run
Code
Output
`; } function run(){ const html = wrapBody(cm.getValue()); // Prefer srcdoc (reliable re-exec), fallback to document.write for older setups if ('srcdoc' in frame) { frame.srcdoc = html; } else { const w = frame.contentWindow || frame; const d = w.document || frame.contentDocument; d.open(); d.write(html); d.close(); } } function reset(){ cm.setValue(INITIAL_CODE); run(); } async function copyCode(){ // Clipboard works on HTTPS (or localhost) try { await navigator.clipboard.writeText(cm.getValue()); runBtn.textContent = '✔ Copied'; setTimeout(()=>runBtn.textContent='▶ Run', 900); } catch { // no-op (likely non-HTTPS context) } } function download(){ const blob = new Blob([wrapBody(cm.getValue())], {type:'text/html'}); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'tryit-example.html'; document.body.appendChild(a); a.click(); a.remove(); URL.revokeObjectURL(url); } runBtn.addEventListener('click', run); resetBtn.addEventListener('click', reset); copyBtn.addEventListener('click', copyCode); downloadBtn.addEventListener('click', download); // Ctrl/Cmd + Enter to run document.addEventListener('keydown', (e)=>{ if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { e.preventDefault(); run(); } }); // Run once on load run();