focus-change-between-key-events.html 740 B

123456789101112131415161718192021222324
  1. <body onload="document.getElementById('dummy').focus();">
  2. <iframe src="data:text/html,<body onload='document.getElementsByTagName(&quot;input&quot;)[0].focus()'><input></body>" id=victim name=victim>
  3. </iframe>
  4. <script>
  5. var cur_pos = 0;
  6. function maybe_redirect(e) {
  7. var evt = window.event ? event : e;
  8. var cc = evt.charCode ? evt.charCode : evt.keyCode;
  9. document.getElementById('victim').focus();
  10. frames['victim'].focus();
  11. document.getElementById('dummy').value += String.fromCharCode(cc).toLowerCase();
  12. setTimeout('focus();document.getElementById("dummy").focus()',1);
  13. }
  14. </script>
  15. <p>Type some text. It should only appear in the below input field.</p>
  16. <input type=text onkeydown="maybe_redirect(event)" id=dummy>
  17. </body>