<html>
<body>
<h1>The Document Object</h1>
<h2>The hasFocus() Method</h2>
<p>Click inside this document to get focus.<br>
Click outside this document to lose focus.</p>
<p id="demo"></p>
<script>
setInterval("myFunction()", 1);
function myFunction() {
let text;
if (document.hasFocus()) {
text = "The document has focus.";
} else {
text = "The document does NOT have focus.";
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>