tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

hasfocus-inner.html (1034B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>hasFocus inner</title>
      6 <script>
      7 var seenFocus = false;
      8 var seenBlur = false;
      9 window.onmessage = function(e) {
     10    if (e.data == "focus") {
     11        let input = document.getElementsByTagName("input")[0];
     12        input.onblur = function() {
     13            seenBlur = true;
     14        }
     15        input.onfocus = function() {
     16            if (seenFocus) {
     17                if (seenBlur) {
     18                    window.parent.postMessage("restored", "*");
     19                } else {
     20                    window.parent.postMessage("noblur", "*");
     21                }
     22            } else {
     23                seenFocus = true;
     24                window.parent.postMessage("focused", "*");
     25            }
     26        }
     27        input.focus();
     28    } else if (e.data == "hasfocus") {
     29        if (document.hasFocus()) {
     30            window.parent.postMessage("wrongfocus", "*");
     31        } else {
     32            window.parent.postMessage("close", "*");
     33        }
     34    }
     35 }
     36 </script>
     37 </head>
     38 <body>
     39 <input>
     40 </body>
     41 </html>