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?

Kara
  • 6,115
  • 16
  • 50
  • 57
Jody Heavener
  • 2,704
  • 5
  • 41
  • 70

3 Answers3

23

Use:

window.open('tel:12345');
Undo
  • 25,519
  • 37
  • 106
  • 129
Tom
  • 4,422
  • 3
  • 24
  • 36
  • 19
    Is that best solution or `window.location.href='tel:12345';` , which one is better ? – adrianTNT Jun 08 '15 at 14:46
  • 10
    @adrianTNT I like your solution better because it doesn't open a new window or tab. It just makes the call from the current window. – chrislebaron Oct 04 '16 at 21:36
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. 
Toby
  • 39
  • 2
  • 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. – Hasip Timurtas Mar 25 '21 at 10:59
-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
  • 1
    Please provide additional details in your answer. As it's currently written, it's hard to understand your solution. – Community Sep 06 '21 at 01:57