focus-event-after-focusing-same-site-iframes-outer.html (847B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>Focus event after focusing same site iframes outer</title> 4 <iframe src="focus-event-after-focusing-iframes-inner.html"></iframe> 5 <script> 6 let outerlog = "outerlog:"; 7 8 let iframe = document.querySelector("iframe"); 9 window.onmessage = function(e) { 10 if (e.data == "start") { 11 window.onfocus = function() { 12 outerlog += "windowfocus,"; 13 }; 14 } else if (e.data == "focus") { 15 outerlog += "willfocusiframe,"; 16 document.querySelector("iframe").focus(); 17 outerlog += "didfocusiframe,"; 18 } else if (e.data == "getlog") { 19 iframe.contentWindow.postMessage("getlog", "*"); 20 } else { 21 opener.postMessage(outerlog + e.data, "*"); 22 } 23 }; 24 25 window.onload = function() { 26 window.onblur = function() { 27 outerlog += "windowblur,"; 28 }; 29 30 opener.postMessage("ready", "*"); 31 }; 32 </script>