JSFiddle - React, Tailwind, and code Playground

HTML

<div>Reloaded #<span id="reloadCount">0</span> time(s)</div>
<button type="button" onclick="openWindow()">
Open child window
</button>

JavaScript

function reloader() {
	if (!reloader.id) {
  	reloader.id = 0;
  }
  document.querySelector('#reloadCount').innerHTML = ++reloader.id;
}

function openWindow() {
  var win = window.open('about:blank', 'blank', 'width=640,height=480');
  win.document.write('<html><head><body><h1>Reloads on close</h1></body></html>');
  win.addEventListener('beforeunload', function() {
    reloader();
    return true;
  });
}