0

I'm trying to write an extension that takes text typed by user in real time. I've succeeded to take text from textarea etc in web pages. but not from composed mail area in gmail, I believe that the main problem is that the composed mail box appears only after clicking on the 'compose' button.

This is my code:

$( document ).ready( function() {
    $('div, input, textarea, html, iframe').focus( function() {
        $(this).keyup(function(){
            var text = $(this).val();
            console.log("text: " + text );

        });
    });
 });

Can someone help me understand how to manage in taking the text from the composed message body?

rsanchez
  • 14,467
  • 1
  • 35
  • 46
Jonathan R.
  • 211
  • 2
  • 4
  • See http://stackoverflow.com/questions/8110934/direct-vs-delegated-jquery-on – rsanchez Mar 15 '15 at 15:21
  • When I'm using the .on() function in a regular html page it works. But in order to write a mail on gmail I need to open a message box using to compose button and for some reason when I type in the message box the function doesn't work. this is the code: ' $('body').on("keypress","iframe",function() {console.log("check");});' @rsanchez – Jonathan R. Mar 16 '15 at 08:41

1 Answers1

1

iframe is different. You will probably have to inject your code into the iframe separately for it to work, and that code would be somewhat sandboxed from the rest of the code (i.e. like a separate page).

It is not clear how you are injecting the javascript, but the documentation at https://developer.chrome.com/extensions/tabs#method-executeScript shows that you can use allFrames parameter property to specify that you want to include it on frames (including iframes)).

Steve Campbell
  • 3,385
  • 1
  • 31
  • 43
  • He probably injects it via manifest, and the reason it's not working is that this iframe is created dynamically after the injection happens. It needs to be re-injected after the compose window opens. – Xan Mar 17 '15 at 11:05
  • thanks, the answer is here: [link](http://stackoverflow.com/questions/9424550/how-can-i-detect-keyboard-events-in-gmail) – Jonathan R. Mar 18 '15 at 21:33