简体   繁体   中英

Send Facebook chat messages via JavaScript

I am writing a Firefox addon, which should be able to send/intercept Facebook chat messages, while chatting in the browser.

I am able to intercept messages, but I don't know, how to trigger the message sending event autonomously.

As I could not find out how to make the ajax request for sending a message myself, my approach was to fill the chat box textarea and then trigger the keydown -Event for ENTER to create and submit a message.

I guess there is a more appropriate and clean way to accomplish this? How can I trigger the AJAX event for sending a message in an open chatbox via JavaScript?

To fire an AJAX request from a text box input would be to check the character code that you input, which for enter would be

if(characterCode == 13)

Which could then be used to fire the request; a full example would be

$("textarea").live("keydown",function(e){
    if (e.which == 13){
        $.ajax({
             //you know the rest
        });
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM