JSFiddle - React, Tailwind, and code Playground

by sfoster

HTML

<button onclick="openPopup(); return false">
Print me from popup
</button>

JavaScript

const url = "data:text/html,%3Ch1%3EHello%2C%20World%21%3C%2Fh1%3E";
var windowObjectReference = null; // global variable

function openPopup() {
  if(windowObjectReference == null || windowObjectReference.closed)
  /* if the pointer to the window object in memory does not exist
     or if such pointer exists but the window was closed */

  {
    windowObjectReference = window.open(url,
   "SomePopup", "width=200,height=600,resizable,scrollbars,status");
    /* then create it. The new window will be created and
       will be brought on top of any other window. */
  }
  else
  {
    windowObjectReference.focus();
    /* else the window reference must exist and the window
       is not closed; therefore, we can bring it back on top of any other
       window with the focus() method. There would be no need to re-create
       the window or to reload the referenced resource. */
  }
}