简体   繁体   English

使用 Javascript 触发电话

[英]Trigger phone call with Javascript

I would like to trigger a tel:12345 HREF using only Javascript, not with an anchor.我想仅使用 Javascript 而不是锚点来触发tel:12345 HREF。 I simply want to grab the value of an input field and use JS to prompt the user to call the number typed in. My trigger will be a button located next to the field.我只想获取输入字段的值并使用 JS 提示用户拨打输入的号码。我的触发器将是位于该字段旁边的按钮。

Suggestions?建议?

用:

window.open('tel:12345');
<button onclick="myFunction()">
Call
</button>

function myFunction(){
var a = document.getElementById('input').value;
window.location.href = 'tel:' + a;
}
You can also view the live version on my website:
https://www.theharnishes.com/phone.html

Here we make a button and assign a function to it that bassically select the input, get the value, and the window.location.href will have the value of the input and it'll sent the url to call any number. 

Js call making is very simple. js调用非常简单。 Using our : onclick function , Location , and tel We can do this in any tag, window .使用我们的 : onclick 函数、 Location 和 tel 我们可以在任何标签 window 中执行此操作。 location ('tel:number')位置('电话:号码')

Click me to call 199 点击我拨打199

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM