JavaScript onclick script to launch native mail client with subject and body text

StackOverflow https://stackoverflow.com/questions/22996670

  •  01-07-2023
  •  | 
  •  

Question

I'm using Flexpaper Zine in an iPad web app as my PDF reader. I love that it is easy to use and customize.

I was asked to add an e-mail button to the toolbar so customers viewing the app can e-mail themselves the PDF.

I figured out how to add the button to the toolbar, however, setting the button do what I want is my dilemma.

The administrator from Flexpaper says to simply add a JavaScript to the tag where the custom button is. I have:

<element type="button" id="bttnEmail" height="14" width="13" onclick="myscript()" />

but I don't know what to write for the script. On click (or on tap, since it's a mobile device), I want the native mail application to launch without a prepopulated mailto, but I do want to prepopulate the subject line and add a link to the PDF in the body.

Is it possible that this isn't possible?

Était-ce utile?

La solution

I have not worked with Flexpaper so far but the following snippet works in a browser address bar

mailto:?subject=My%20subject&body=message%20goes%20here

And encapsulated in a function

function myscript() {
    window.location = "mailto:?body=Your content&subject=Mail Subject";
}

Please let me know when the window object is not available or it does not work.

Useful links

Automically open default email client and pre-populate content

Open an email program with subject and body prefilled is not working correct

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top