How to open the gmail app on mobile

Asked

Viewed 63 times

-4

I know that to open the maps is like this:

window.location = "geo:?q="+endereco;

To open the phone dial is like this:

 window.location = "tel:"+telefone1;

To open the message screen (sms):

window.location = "sms:"+telefone;

Now, how do I open the email?

  • Have you tried window.location.href = "mailto:[email protected]" this should open the user’s default email client...

1 answer

1


Chrome on Android is blocking redirects to applications that are not done through a user gesture.

Therefore, via javascript it is not possible to redirect the user to the email application, since Chrome 40, only if you put it for example on a href button, which will work when the user clicks the button.

Here’s a discussion on the subject in the Chrome forum.

If you inspect the element you see a message like

Navigation is blocked: mailto:?...


You can try to do this way, as I mentioned before that is by adding a href.

var email = document.createElement('a');
email.style.visibility = 'hidden';
email.style.position = 'absolute';
email.href = 'mailto:[email protected]?subject=subject&body=body';
document.body.appendChild(email);

And after that when you run you can do so.

email.click();
  • Thank you, that’s right!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.