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?