linto cheeran
linto cheeran

Reputation: 1472

javascript mailto not working in chrome mobile browser

mailto via javascript not working in mobile chrome browser

window.location.href = "mailto:[email protected]?subject=subject&body=body"

is not working in mobile google chrome browser

actual source

Upvotes: 2

Views: 4207

Answers (3)

Tim T
Tim T

Reputation: 1

On my site, when people click on what they believe to be mailto links (same restrictions apply on tel: links, by the way), I first send a GA event, and then use window.location to initiate the mailto. While Chrome will give me the warning via the dev console, it still processes the tel/mailto request, and the window still pops up.

Upvotes: -2

AntonB
AntonB

Reputation: 2853

I am posting an answer as this is possible.

Create a hidden from view / temporary link element and simulate the click.

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

and later when you want to trigger and open the mail client:

linkElement.click();

Upvotes: 0

Daniel Azeiteiro
Daniel Azeiteiro

Reputation: 31

Chrome on Android is blocking the redirects to apps that are not made via a user gesture.

So via javascript it's not possible to redirect the user to the mail app since Chrome 40, only if you put it for example in a button href, that will work when user clicks the button.

You can read more in chromium forum

If you inspect the Chrome console you will a warning, something like: Navigation is blocked: mailto:?...

Upvotes: 3

Related Questions