<input type="text" id="writeToMe">
window.onload = function(){
var event;
//click handler
.addEventListener("click",function(){
alert("clicked");
},false);
//This is true only for IE and firefox
if(document.createEvent){
// To create a mouse event , first we need to create an event and then initialize it.
event = document.createEvent("MouseEvent");
event.initMouseEvent("click",true,true,window,0,0,0,0,0,false,false,false,false,0,null);
}
else{
event = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true,
key: "Q",
Char:"Q"
});
}
writeToMe.dispatchEvent(event);
};