JavaScript Click on the Link to Send Email
Introduction
There is a link on the page, clicking on this link triggers the function of sending an email
Code
Implemented using HTML and JavaScript. Here is an example:
<!DOCTYPE html>
<html>
<head>
<title>Send Email Link</title>
<script>
function sendEmail() {
window.location.href = "mailto:recipient@example.com?subject=Hello&body=Hello, this is the email content.";
}
</script>
</head>
<body>
<a href="#" onclick="sendEmail(); return false;">Click to send email</a>
</body>
</html>
In the above example, we created a simple HTML page and added a link on the page. When the user clicks on the link, the sendEmail()
function will be called. In this function, we use window.location.href
to redirect the user to the email client, opening a new email composition window.
Note that the link in the example above is just a placeholder, you'll need to replace it with the actual recipient addresses, subject, and content of the email you want to send.
Also, it should be noted that this method relies on whether a default mail client is already installed on the user's device, and that the client can handle the mailto
protocol. In some cases, this method may not work properly if the user's device does not have a default mail client or the browser is configured with special settings.
Comments