Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bind multiple actions to a keyboard event
    primarykey
    data
    text
    <p>I am trying to make a chrome extension that modifies the text in an active text area of a Facebook chat window. But I want the change to take place only when the user presses the enter key so that the text doesn't change while it is still in the textarea. I want it to happen using javascript and make it feel like it's happening in the background although I want it to get triggered on the <code>keydown</code> event of the <kbd>enter</kbd> key. </p> <p>Now the relevant JavaScript for the chat window's textarea in Facebook is:</p> <pre><code>&lt;textarea class="blah" onkeydown="window.Bootloader &amp;&amp; Bootloader.loadComponents(["control-textarea"], function() { TextAreaControl.getInstance(this) }.bind(this)); "&gt; &lt;/textarea&gt; </code></pre> <p>And in my extension's JavaScript file. I bind the <code>keydown</code> event using something like this:</p> <pre><code>//elem is bound to the focussed textarea object elem.onkeydown = function(evt) { if(evt.keyCode == 13){ //Some javascript code I want to execute here... } }; </code></pre> <p>I think as soon as the user presses the <kbd>enter</kbd> key, the textarea is cleared and some sort of a post request is made. So I lose the scope of the text I wanted to modify using JavaScript. I checked that the enter key binding is working for my extension by pressing <kbd>shift</kbd> + <kbd>enter</kbd>, and it modified the text without a problem. So my script is working fine.</p> <p>However I want my script to be executed before the textarea is cleared and the post request is made. I just don't want the user to see the text getting modified.</p> <p>Can I add/modify the keybinding of the textarea used by Facebook as shown above in my script for the google chrome extension? Any help is deeply appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload