Anirban Hajra
Anirban Hajra

Reputation: 26

Automatic target a phone call when my html page is refresh

I need to create a jquery code to call a number on page loading. The code is added but it not working with the phone.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=0" />
        <meta name="description" content="">
        <meta name="author" content="">
        <title>test</title>
    </head>
    <body>
        <a id="add_redirect" href="tel:+1-541-754-3010">Call</a>
    </body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            $("#add_redirect").trigger("click");
        });
    </script>
</html>

Upvotes: 0

Views: 121

Answers (2)

Bram Verstraten
Bram Verstraten

Reputation: 1557

Always supply the phone number using the international dialing format: the plus sign (+), country code, area code, and number. While not absolutely necessary, it’s a good idea to separate each segment of the number with a hyphen (-) for easier reading and better auto-detection.

For example:

tel:+1-303-499-7111

More info here.

The click event doesn't work for hyperlinks. You can use this workaround instead:

$(document).ready(function() {
    var href = $("#add_redirect").attr('href');
    window.location.href = href;
});

Upvotes: 1

MD. RAKIB HASAN
MD. RAKIB HASAN

Reputation: 3956

$(document ).ready(function() {
  $("#add_redirect").trigger('click');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a id="add_redirect" href="tel:+012345678">Call</a>

Upvotes: 0

Related Questions