I am trying to send text messages on whatsapp web version on chrome. (www.web.whatsapp.com)
This is the code:
$(".input").on("keypress",function(e){
if(e.which == 32 || e.which == 13){ alert('msg sent')};
});
you have to compare == where as you are assigning =
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'));
}