I wonder how you do to get the phone number with Avascript

Asked

Viewed 119 times

-3

The code I’m working on.

var x = document.getElementsByTagName("details-contact")[1].innerHTML
    
function abreLink() {
  var url = 'https://api.whatsapp.com/send?phone=55' + x + '&text=Ola%2C%20gostaria%20de%20saber%20mais%20sobre%20seus%20produtos%20e%20serviços.';
  document.write(url);
}
<div class="details-contact">
  <div class="contact-item item-phone">
    <span class="icon icon-md">...</span>
    <a href="tel:(11) 2222-3333">(11) 2222-3333</a>
  </div>
</div>

  • Do not post images, please. If you want to display your code copy and paste it. Otherwise it makes it difficult (and too difficult) for other people to help you.

  • Was able to verify the responsta?

1 answer

0

I was in doubt whether it answered the enunciation or the purpose of the code...

Starting with the purpose:

function abreLink(link) {
  var url = 'https://api.whatsapp.com/send?phone=55' + link.text + '&text=Ola%2C%20gostaria%20de%20saber%20mais%20sobre%20seus%20produtos%20e%20serviços.';

  document.write(url);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<a href="tel:(11) 2222-3333" onclick="abreLink(this); return false;">(11) 2222-3333</a>

Going by the code presented: The use of getElementsByTagName is incorrect in this case, once you pass a class in place of an html tag. The easiest in this case would be to add an id to the phone link and use the method getElementById.

<a id="id_do_telefone" href="tel:(11) 2222-3333">(11) 2222-3333</a>

var phoneElement = document.getElementById("id_do_telefone").innerHTML
ou até
var phoneElement = document.getElementById("id_do_telefone").text

Browser other questions tagged

You are not signed in. Login or sign up in order to post.