Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JavaScript window.location.href and click() methods doesn't work on mobile phone

I need to redirect the user to phone number. Everything is WORKS FINE ON DESKTOP but window.location.href and click() methods doesn’t work on mobile phone’s browser.

Code 1

        <a href="tel:555-666-7777" id="test">555-666-7777</a>
        <script>
        var element = document.getElementById('test'); 
        element.click();
        </script>

Code 2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

        <script>
        window.location.href="tel:555-666-7777";
        </script>

>Solution :

You must call another tab to use "tel" action, try like this:

  $(function() {
    $('.phone').click(function() {
      var PhoneNumber = $(this).text();
      PhoneNumber = PhoneNumber.replace('Phone:', '_self');
      //PhoneNumber = PhoneNumber.replace('Phone:', ''); or without _self
      window.location.href = 'tel://' + PhoneNumber; 
     // you can use  window.open instead like this: window.open('tel:900300400')
    });
  });

In HTML:

<span class="phone">Phone: 900 300 400</span>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading