Question: I have a page that is used by Doctors, where they can write the patient email select a bounce of documents, and via "mailto" create a formatted email. This doesn't work on Safari iOS.

The problem I found is mailto does not work with Safari iOS if launched from home screen (as a web app). It works using onclick=window.location I tried to implement it on my function but it is not working

so I am trying to implement something like this:

```
<a href="#" onclick="window.location='mailto:me@any.com?subject=Docs&body=Hallo%20you%20and%20links'; return false;" class="noHighlight">Write and email</a>

```

in my function:

```
function buildMailto(recipient, subject, body) {
  var mailToLink = "mailto:" + recipient + "?";
  var mailContent = "Subject=" + subject + "&";
  mailContent += "cc=testemail@gmail.com&";
  mailContent += "body="
  mailContent += encodeURIComponent(body);
  a.href = mailToLink + mailContent;
}

```

I am trying to edit:

```
function buildMailto(recipient, subject, body) {
var mailToLink = " '#'  onclick=\"window.location='mailto:" + recipient +"?";
  var mailContent = "Subject=" + subject + "&";
  mailContent += "cc=testemail@gmail.com&";
  mailContent += "body="
  mailContent += encodeURIComponent(body);
  mailContent +=  "return false;  class='noHighlight' ";
  a.href = mailToLink + mailContent;
}

```

Not having any results at the moment

Answer: 
In your `buildMailto` function, you didn't specify what is `a`. Instead of updating `onclick` attribute value when the anchor link is clicked, you should build a mailto URL and update `window.location.href`. Here is an example:

```
<a href="#" id="email-link" class="noHighlight">Write and email</a>

```

Event listener for anchor link:

```
document.querySelector('#email-link').addEventListener('click', function (e) {
    e.preventDefault();

    buildMailto('me@any.com', 'Docs', 'Hi, there!');
});

```

Change your `buildMailto` to the following:

```
function buildMailto(recipient, subject, body) {
    var mailLink = "mailto:" + recipient + "?";
    mailLink += "Subject=" + subject + "&";
    mailLink += "cc=testemail@gmail.com&";
    mailLink += "body="
    mailLink += encodeURIComponent(body);
    window.location.href = mailLink;
}

```
Try embedding your actionable into a form. Like this:

```
<form action="mailto:me@any.com?subject=Docs&body=Hallo%20you%20and%20links" method="GET">
  <button class="noHighlight" type="submit">Write and email</a>
</form>

```