JSFiddle - React, Tailwind, and code Playground
HTML
<button id="button">Click</button>
JavaScript
document.getElementById("button").addEventListener("click", function() {
var w = window.open();
w.innerHTML = '<html><head></head></html>';
var script = w.document.createElement("script");
script.textContent = "alert('running');";
w.document.getElementsByTagName("head")[0].appendChild(script);
});