Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger phone call with Javascript

Tags:

javascript

tel

I would like to trigger a tel:12345 HREF using only Javascript, not with an anchor. 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.

Suggestions?

like image 512
Jody Heavener Avatar asked May 27 '13 23:05

Jody Heavener


2 Answers

Use:

window.open('tel:12345');
like image 128
Tom Avatar answered Oct 08 '22 15:10

Tom


<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. 
like image 29
Toby Avatar answered Oct 08 '22 17:10

Toby