JSFiddle - React, Tailwind, and code Playground

by Victor

HTML

Hello, please disable your pop-up blocker.

<xmp id="popupcontent">
    <html><head>
    <title>Foo Bar</title>
    <style>
    h1{
        color:blue;
    }
    </style>
    </head><body>
    
    <h1>Hello World!</h1>
    <br>
    <button onclick="window.close()">Close</button>
     
     <script>
         alert("Welcome");
     </script>
        
     </body>
     </html>
</xmp>

CSS

xmp{
    display: none;
}

JavaScript

function pop(html,top,left,width,height) {
    
	var popup = window.open("", "", "width="+width+",height="+height+",top="+top+",left="+left+",toolbar=no");
    if(popup){
        popup.document.open();
        popup.moveTo(top,left);
        
        popup.d = popup.document;
        popup.d.write(html);
    }
    else{
        alert("Popup blocked!");
    }
    return popup;
}

pop(popupcontent.innerHTML, 30, 30, 500, 300);