我正在创建一个扩展,我必须在contenteditable div上模拟一个空格键,用户在Google Plus中键入消息(状态).
如果您打开plus.google.com并点击必须输入消息的div,您会发现当您在消息中键入链接并按{spacebar}时,您会发现Google会检索标题,图片和描述那个链接.我是3天试图模拟空格键盘.我已经可以模拟鼠标悬停在表单的元素上,我可以在发送按钮中模拟click(),但我仍然无法模拟空格键keydown.
到目前为止,我最好的代码是:
var e = new KeyboardEvent("keydown", {bubbles : true, cancelable : true, key : " ", char : " ", shiftKey : false, keyCode: 32, which: 32, view: window});
//I need to delete the e.keyCode and e.which cause Chrome sets it as a readonly but for some reason if you delete it and assign a new value Chrome accepts (I am very sure this is a serious bug that I discovered in Chrome and that I …Run Code Online (Sandbox Code Playgroud)