JSFiddle - React, Tailwind, and code Playground
by fatelei
HTML
<h1>JavaScript hasFocus example</h1>
<div id="message">Waiting for user action</div>
<div><button onclick="openWindow()">Open a new window</button></div>
JavaScript
setInterval( checkPageFocus, 200 );
function checkPageFocus() {
var info = document.getElementById("message");
if ( document.hasFocus() ) {
info.innerHTML = "The document has the focus.";
} else {
info.innerHTML = "The document doesn't have the focus.";
}
}
function openWindow() {
window.open (
"http://developer.mozilla.org/",
"mozdev",
"width=640,
height=300,
left=150,
top=260"
);
}