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: 
There were a few issues with your code:

* `a` was never defined. Give your link an ID and select id by using `document.getElementById()`
* You cannot set the `href` attribute of the link and "break out" using double quotes in order to add the onclick attribute to the element. Instead:
* add the `click` event using `.addEventListener()`. Alternatively, you could use `.setAttribute('onclick', 'window.location.href = "' + mailToLink + mailContent + '"; return false;');` if you wanted to be able to see the click event using your browser's DOM inspector, but it doesn't really make sense.

```js
function buildMailto(recipient, subject, body) {
var mailToLink = "mailto:" + recipient +"?";
  var mailContent = "Subject=" + subject + "&";
  mailContent += "cc=testemail@gmail.com&";
  mailContent += "body="
  mailContent += encodeURIComponent(body);
  document.getElementById('myLink').addEventListener('click', function() {
    window.location.href = mailToLink + mailContent;
    return false;
  });
}

buildMailto('foo@bar.baz', 'a subject', 'mail content');
```

```html
<a href="#" id="myLink" class="noHighlight">Write and email</a>
```
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>

```