How to open `tel:+48123` link client side without openning new window/tab in browser

13,090

Solution 1

The solution is much easier:

document.location.href="tel:"+the_number;

Solution 2

Ok. This is little cheat and it works on Chrome, but does not work on IE, which I use in development of ASP .NET MVC Web Apllications.

   function Call(){
        document.getElementById('mymailto').click();
    }

and in HTML

<a href="tel:+48123456" id="mymailto" style="display:none"></a>

Solution 3

window.open("tel:888", "_self");

Second argument is same to "target" attribute of 'a' tag. Here is an explanation what's target: https://www.w3schools.com/tags/att_a_target.asp So "_self" means current frame (=current page in most cases)

Share:
13,090
Employee
Author by

Employee

Updated on June 05, 2022

Comments

  • Employee
    Employee almost 2 years

    I need to deliver the same behaviour if I clicked tel:+4842566 link by myself. The default telephony application should call the number nothing more.

    I managed that besides that new tab opens. I wrote:

    function Call(){
        window.open("tel:+4842566",'_blank');     
    }
    

    and this:

    function Call(){
        window.open("tel:+4842566");     
    }
    

    and this:

      function Call(){
            document.getElementById('mymailto').click();
        }
    
    
    <a href="tel:+48123456" id="mymailto" style="display:none"></a>
    

    Results are the same. Computer calls the number but new tab is openned.

    Question: Is it possible to invoke/open this link without new tab/window?

    EDIT: Before I tried to run this client side I did it on server side but did not realise that when I deploy application it is not the client who will be calling:

    public ActionResult Call(int id, string number) {
      System.Diagnostics.Process proc = new System.Diagnostics.Process();
        string formattedNumber = "tel:+48" + formatPhoneNumber(number);
        System.Diagnostics.Debug.WriteLine("NUMBER " + formattedNumber);
        proc.StartInfo.FileName = formattedNumber;
        proc.Start();
        Person person = db.Persons.Find(id);
        return RedirectToAction("Edit", new Person { Id = id });
    }
    

    but then I didn't get new tab, maybe it will help somehow.

    EDIT 2: I don't simply look for href link cause launching tel: link is only one of 2 things that happen at the same time:

    <p>@Html.ActionLink("Call Cell Phone", "Call", new { id = Model.Id, number = Model.CellNumber }, new { @class = "btn btn-default", onclick = "Call();" })</p>
    

    I go to the controller action and invoke Call() javascript method and JavaScript method is the only place that simple openning any link can be done.

  • Andreas Linnert
    Andreas Linnert over 6 years
    Yes, this works. But you should use an equal sign to make an asignment :) document.location.href = 'tel:0123...'