Is it possible to programmatically call a telephone number in JS?

最后都变了- 提交于 2020-12-01 03:52:20

问题


So basically right now I can create a button with an A tag that has an href="tel:XXXXXXXXXXX" and if a user clicks / taps on that it will bring them into their phone application. However I am trying to do this programmatically on gesture recognition (swipe). The gesture is working, so far I have tried window.location = "tel:XXXXXXXXXX"; window.open('tel:XXXXXXXXXX', '_top');

neither of which have worked yet. Any idea? Ionic / Angular 1

Note** It appears to only happen on iOS, Android seems to be working fine.


回答1:


If you want to do it through html, then you just have to place a tag like this:

<a href="tel:XXXXXXXXXX">Call me!</a>

similarly if you wanna do it through javascript, you can do:

document.location.href = "tel:XXXXXXXXXX";



回答2:


For this you will require to add this in the config.xml first

<access origin="tel:*" launch-external="yes" />

then call it like:

document.location.href = "tel:XXXXXXXXXX";

Whitelist Guide




回答3:


You probably just can't, when your APP is running from mobile browser. You'll need to wrap your app as cordova app or similar. Then you can for example use PhoneGap-PhoneDialer




回答4:


You can try with below one,

window.location.href = "tel:+91123456789";

But, for IOS it may not work because of some permission issues. In that case you can try like below,

window.open('tel:+91123456789', '_system');



回答5:


Try it on a real device.

None of these methods worked on the IOS emulator. It only worked on a physical device. That tripped me up for a while.



来源:https://stackoverflow.com/questions/40333051/is-it-possible-to-programmatically-call-a-telephone-number-in-js

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