简体   繁体   English

如何在iPhone上的Web应用程序中发起电话

[英]How to initiate a phone call in a web app on iPhone

I want to implement a JavaScript API to initiate phone calls programmatically and without the need for a native Objective-C implementation. 我想实现一个JavaScript API,以编程方式发起电话,而无需本机Objective-C实现。

What I tried so far was something like location.href='tel:12345'; 到目前为止,我尝试过的操作类似于location.href='tel:12345'; . The result was an error with the message "The URL can't be shown". 结果是出现错误消息“ URL无法显示”。

My second attempt was to create a hidden link (like <a href="tel:12345">call</a> ) and click it programmatically. 我的第二次尝试是创建一个隐藏的链接(例如<a href="tel:12345">call</a> )并以编程方式单击它。 This didn't work either, although the link worked when not hidden and clicked manually by the user. 尽管该链接在未隐藏并由用户手动单击的情况下仍有效,但这也不起作用。

Is it possible to achieve this with JavaScript only or do I need to delegate to the Objective-C part of the application to initiate the call from there? 是否可以仅使用JavaScript来实现此目的,还是需要委托给应用程序的Objective-C部分从那里发起调用?

您是否尝试过tel://12345而不是tel:12345 tel://12345

<a href="tel:1-800-xxx-xxxx">call</a>

您的网址正确吗?

为此使用window.open()

window.open( 'tel:800-888-1234', '_top' );

您可能必须本地编写代码并创建一个JavaScript函数以从WebView中调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM