initKeyEvent er ikke en funktion i webkit
HejNedestående kode virker ikke i webkit, da der ikke er nogen initKeyEvent funktion. Hvilken funktion skal man så bruge for at simulere et tastetryk?
<!DOCTYPE html>
<html lang="da">
<head>
<title>oninput</title>
<meta charset="utf-8">
</head>
<body>
<input value="long string in input value">
<script type="text/javascript">
var oninput = function (event) {
console.log(event);
console.log(event.charCode); //undefined
console.log(event.keyCode); //undefined
}
if (document.addEventListener) {
var input = document.getElementsByTagName('input')[0];
input.addEventListener('input', oninput, false);
var e = document.createEvent("KeyboardEvent");
e.initKeyEvent("keypress",true, true, null, false, false, false, false, 8, 0); //Simulate delete
input.dispatchEvent(e);
}
</script>
</body>
</html>