javascript 如何在php网站中点击按钮触发电话?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23857507/
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 01:42:01  来源:igfitidea点击:

how to trigger a phone call on button click in a php website?

javascriptphpjqueryhtmlcss

提问by Bhavik

My client needed a hyperlink for a click to call feature so i include following line

我的客户需要一个点击呼叫功能的超链接,所以我包括以下行

<a href="tel:917387084384">Call +91-7387084384</a>

However, requirements have changed from hyperlink to button, so need to know how to include click to call feature with a button

但是,要求已从超链接更改为按钮,因此需要知道如何使用按钮包含点击呼叫功能

please let me know if you need any clarifications from my side. thanks.

如果您需要我方面的任何说明,请告诉我。谢谢。

回答by Joeytje50

You could simply style the button to look exactly like a button, or you could use an onclickevent handler:

您可以简单地将按钮的样式设置为与按钮完全一样,或者您可以使用onclick事件处理程序:

<button onclick="document.location.href = 'tel:917387084384'">Call +91-7387084384</button>

回答by hakre

Step-by-step guide to turn a hyperlink into button:

将超链接转换为按钮的分步指南:

  1. Rename the atag into formand the hrefattribute into action:

    <form action="tel:917387084384">Call +91-7387084384</form>

  2. Wrap the text into a buttontag:

    <form action="tel:917387084384"><button>Call +91-7387084384</button></form>

  3. Add the typeattribute to the buttontag and set it to submit:

    <form action="tel:917387084384"><button type="submit">Call +91-7387084384</button></form>

  1. a标记重命名为form,将href属性重命名为action

    <form action="tel:917387084384">Call +91-7387084384</form>

  2. 将文本包装成一个button标签:

    <form action="tel:917387084384"><button>Call +91-7387084384</button></form>

  3. type属性添加到button标记并将其设置为submit

    <form action="tel:917387084384"><button type="submit">Call +91-7387084384</button></form>

And you're done!

大功告成!

回答by oabarca

The following will make the browser ask you for permission to launch Skype when clicked:

单击以下内容时,浏览器将要求您授予启动 Skype 的权限:

<button onclick="window.location='tel:917387084384';">Hot line</button>