This is my code:
<script>
function f(){
var i=document.getElementById("i");
i.focus();
var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, null, false, false, false, false,
0, 32);
i.dispatchEvent(evt);
}
</script>
<body onload="f();">
<input id="i"/>
</body>
Open the script in firefox and it's working. The empty space within the input box shows that the code has worked.
However the above piece of code doesn't work in Chrome, Safari, Opera etc etc.
How do we modify the code above to make it work in these browsers?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…