javascript 如何打开电话拨号器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25122713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:58:58  来源:igfitidea点击:

How to open the phone dialer?

javascripthtmlcordovaibm-mobilefirst

提问by user3878988

I am trying to launch the phone dialer in my worklight 6.2 hybrid application when clicking on a button and/or an anchor tag. Below is the code I am using.

单击按钮和/或锚标记时,我试图在我的 worklight 6.2 混合应用程序中启动电话拨号程序。下面是我正在使用的代码。

button:

按钮:

<button onClick='window.parent.location.href = "tel:+1xxxx"'>Tel</button>

anchor tag:

锚标签:

<a href='tel:+18001111111' class="ui-link">(800) 111-1111</a>  

When we click on button/anchor tag below is the behavior in android and iOS.
In android:

当我们点击下面的按钮/锚标签时​​,是安卓和 iOS 中的行为。
在安卓中:

Displays a pop up window with the message

显示带有消息的弹出窗口

Application Error net::ERR_UNKNOWN_URL_SCHEME (TEL:+18001111111)

应用程序错误 net::ERR_UNKNOWN_URL_SCHEME (TEL:+18001111111)

In iOS:

在iOS中:

The click event doesn't respond.

点击事件没有响应。

回答by Idan Adar

Are you testing in the iOS Simulator? if so, you must test in a device.
For Android, you can test in either the Emulator or a device.

您是否在 iOS 模拟器中进行测试?如果是这样,您必须在设备中进行测试。
对于 Android,您可以在模拟器或设备中进行测试。

The following worked for me in an iOS device:

以下内容在 iOS 设备中对我有用:

  • <a href="tel:+1-800-555-1234">call this number</a>
    Can be invoked right from the HTML

  • document.location.href = "tel:+375292771265";
    Can be invoked via a function on button tap

  • <a href="tel:+1-800-555-1234">call this number</a>
    可以直接从 HTML 调用

  • document.location.href = "tel:+375292771265";
    可以通过按钮点击的功能调用

As for Android,

至于安卓,

Due to security bugs in Cordova (and the fixes made to counter them), to get the above code to work, you need to open native\res\xml\config.xml and perform the following:

由于 Cordova 中的安全漏洞(以及针对这些漏洞所做的修复),要使上述代码正常工作,您需要打开 native\res\xml\config.xml 并执行以下操作:

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

回答by rangholiya nikunj

this cordova plugin are use

这个cordova插件正在使用

mx.ferreyra.callnumber 0.0.2 "Cordova Call Number Plugin"

Code

代码

   <ion-fab left bottom>
    <a href="tel:number" class="button" ion-fab color="light">
        <ion-icon name="keypad"></ion-icon>
    </a>
</ion-fab>

回答by Navnath Adsul

If you are using like this <a href="tel:+1-800-555-1234">call this number</a>and you still getting an error saying ERR_UNKNOWN_URL_SCHEMEthen use cordova-plugin-invokedialer.

如果您像这样使用<a href="tel:+1-800-555-1234">call this number</a>并且仍然收到错误消息,请ERR_UNKNOWN_URL_SCHEME使用cordova-plugin-invokedialer.

cordova-plugin-invokedialer- npm

科尔多瓦插件-invokedialer-npm