Trigger phone call with Javascript
Asked Answered
R

3

12

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?

Recognizor answered 27/5, 2013 at 23:24 Comment(5)
Have you tried anything?Harrod
Tadaaaaa! developer.mozilla.org/en-US/docs/Web/API/WindowCryptograph
Some punk is going to put 911 in that input field.Backwater
Or worse, some botnet will hammer it on behalf of all it's owned users.Backwater
Possible duplicate of HTML Phone call with mobile device (href="tel:") and javascriptCally
R
24

Use:

window.open('tel:12345');
Righteous answered 27/5, 2013 at 23:25 Comment(2)
Is that best solution or window.location.href='tel:12345'; , which one is better ?Forgiven
@Forgiven I like your solution better because it doesn't open a new window or tab. It just makes the call from the current window.Brogdon
S
1
<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. 
Stingaree answered 24/3, 2021 at 23:42 Comment(1)
Please don't post only code as an answer, but also provide an explanation of what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.Beauvoir
V
-1

Js call making is very simple. Using our : onclick function , Location , and tel We can do this in any tag, window . location ('tel:number')

Click me to call 199
Velarium answered 6/9, 2021 at 0:48 Comment(1)
Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.Horsy

© 2022 - 2024 — McMap. All rights reserved.