There are some web,I type the code below not working.For example,I type the code in console at Bing(a search engine)
var event;
event = document.createEvent('Event');
event.initEvent("keypress", true, true);
event.view = window;
event.keyCode = 13;
event.which = 13;
event.charCode = 13;
event.code = "Enter";
event.key = "Enter";
event.bubbles = true;
and i have already type some text in the search bar, the element's id is "sb_form_q",so
var element = document.getElementById("sb_form_q");
element.dispatchEvent(event);
it will return true, but actually nothing happen. I have tried many webs, some working, some not working, and i don't know why.
2018/8/3 update:
I know why some web page dispatch "Enter" event don't work,cause the input is not submit by "Enter" key, but by submit or onsubmit event.