JSFiddle - React, Tailwind, and code Playground

by Ankit Sharma

HTML

<h1>JS Onblur example</h1>
  <h2>Try to open new tab, i dare you !</h2>
  <h3>But first click here to set focus :P</h3>

JavaScript

var hasFired = false;
window.onblur = function () { 

  if(!hasFired){
            hasFired = true;// use this variable to fire this only once
            confirm('trying to switch tabs eh !');
        }
   
};