How to add mailto link using JavaScript?

Sometimes, we want to add mailto link using JavaScript.

In this article, we’ll look at how to add mailto link using JavaScript.

How to add mailto link using JavaScript?

To add mailto link using JavaScript, we set the window.location.href value.

For instance, we write

window.location.href = "mailto:[email protected]";

to set window.location.href to "mailto:[email protected]" to open the default email client with the to field set to [email protected].

Conclusion

To add mailto link using JavaScript, we set the window.location.href value.