How do I insert a Share button in WhatsApp into HTML projects?
How do I insert a Share button in WhatsApp into HTML projects?
You can use the URL scheme whatsapp://send?text=
in the href
attribute of a hyperlink followed by the message that will be shared. For example:
<a href='whatsapp://send?text=StackOverflow'>compartilhar</a>
If the user has the application installed, it will be initialized allowing a contact to be chosen next to a text field that allows editing the message before sending.
Because the browser is still not able to access WhatsApp the way it is done on mobile devices - this URL scheme is unknown - it may be interesting to hide that link and display it only on smaller screens:
/**
* Tamanho somente para ilustrar! Tenha em mente que
* a instalação do aplicativo não é restrita a smartphones.
*/
@media screen and (min-width: 860px){
.compartilhar-whatsapp {
display: none;
}
}
Some links in frequently asked questions about the application that cites the use of this custom url schema: