I am trying to send text- messages on WhatsApp with javascript?

后端 未结 8 749
粉色の甜心
粉色の甜心 2020-12-30 16:54

I am trying to send text messages on whatsapp web version on chrome. (www.web.whatsapp.com)

This is the code:

相关标签:
8条回答
  • 2020-12-30 17:42
    $(".input").on("keypress",function(e){ 
     if(e.which == 32 ||  e.which == 13){ alert('msg sent')};
    
    });
    

    you have to compare == where as you are assigning =

    0 讨论(0)
  • 2020-12-30 17:45

    Firing an event with a KeyPress into an input will not actually populate the text area because the population is part of the native event.

    If your intention is to populate a text field, you'll simply need to set the val. In jQuery this can be done with .val(), e.g.:

    function pressKey() {
      $(".input").val('test');
    }
    

    The WhatsApp input box probably has an event listener waiting for a keyup event, and if the field is populated, switching it to the send button. If this is the case then you can manually trigger an event which will trigger WhatsApp's (non-native) code.

    function pressKey() {
      $(".input").val('test').trigger($.Event('keyup'));
    }
    
    0 讨论(0)
提交回复
热议问题