1
我想寫一個可以使用Skype for web發送消息的Chrome擴展程序(https://web.skype.com/en/)。我可以在textarea中獲取文本,但我無法觸發Enter鍵。如何歸檔這個?Skype的Web擴展按鍵
擴展程序獲取加載好,並在輸入字段中放置一個文本,但它停止。我也嘗試開始改變事件和輸入事件。但沒有任何反應。
我正在使用等待功能,因爲Skype需要一段時間才能加載。
我的manifest.json
{ "manifest_version": 2, "name": "SkypeTest", "version": "0.0.1",
"content_scripts": [{"matches": ["https://web.skype.com/*"],
"js": ["jquery-2.1.4.min.js", "skypeTest.js"]}]}
我skypeTest.js
;(function() {
var e = jQuery.Event('keydown', { which: 13 });
function init(){
console.log('Script running');
var wait = function() {
var txtArea = $("textarea[name='messageInput']");
if (txtArea.is(':visible')) {
clearTimeout(waiting);
txtArea.val('Hello Skype');
txtArea.trigger('focus').trigger(e);
}
};
var waiting = setInterval(wait, 5000);
}
init();
})();
這是輸入字段
<textarea tabindex="10010" maxlength="2000" data-bind="value: messageBody, css: {hide: !isEnabled()},
valueUpdate: ['afterkeydown','propertychange','input'],
event: { keypress: handleKeyPress, keydown: handleKeyDown, input: handleInput,
focus: onFocus, blur: onBlur, paste: onPaste }, hasFocus: chatInputFocus,
l10n_attr: {'placeholder': 'area_text_insertText'}, attr: { 'aria-label': label },
template: { afterRender: handleFocus }" name="messageInput" class="inputField fontSize-p" placeholder="Type a message here"
aria-label="Chat input" style="height: 30px;"></textarea>
請參閱[this](https://code.google.com/p/chromium/issues/detail?id=52408)和[this](https://bugs.webkit.org/show_bug.cgi?id = 16735) – wOxxOm
謝謝@wOxxOm。我知道Chrome中的錯誤。但這似乎是別的。在調試器中,我可以看到指定了正確的keyCode: n.Event {type:「keydown」,其中:13,timeStamp:1436756197584,jQuery2140713275273796171:true} –