| <!DOCTYPE html> |
| <input id="target" value="This should be unfocused!"></input> |
| |
| <script> |
| let got_focus = false; |
| document.getElementById("target").addEventListener("focus", () => { |
| got_focus = true; |
| }); |
| |
| window.addEventListener("load", () => { |
| parent.postMessage("child_loaded", "*"); |
| }); |
| |
| window.addEventListener("message", event => { |
| if (event.data == "attempt_to_focus") { |
| document.getElementById("target").focus(); |
| let msg = got_focus ? "child_is_focused" : "child_is_not_focused"; |
| parent.postMessage(msg, "*"); |
| } |
| }); |
| </script> |