1$(window).on("blur focus", function(e) {
2 var prevType = $(this).data("prevType");
3
4 if (prevType != e.type) { // reduce double fire issues
5 switch (e.type) {
6 case "blur":
7 // do work
8 break;
9 case "focus":
10 // do work
11 break;
12 }
13 }
14
15 $(this).data("prevType", e.type);
16})