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

て烟熏妆下的殇ゞ 提交于 2019-12-07 21:31:13

问题


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.


回答1:


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>



回答2:


The solution is much easier:

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



回答3:


The solution for this is:

var call_app = window.open("tel:"+$(this).text(), "_blank");
call_app.close();


来源:https://stackoverflow.com/questions/25703925/how-to-open-tel48123-link-client-side-without-openning-new-window-tab-in-bro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!