javascript - 打开tel:XXXXXXXXXX时如何通过JS添加CORS
问题描述
如果我们从 Android 手机访问,我需要通过 Java 脚本打开本机拨号程序。由于ionincframework不允许通过普通代码打开本机拨号程序,因此做了一些研究并了解到由于 CORS 它无法打开。在使用 tel:XXXXXXXXXXX 协议之前尝试使用以下代码应用 CORS,但无法正常工作。
<html>
<div class="phoneLinkDiv" onclick="javascript:createCORSRequest('POST','tel:555-999-8888');" data-rel="external">Hello</div>
<a href="tel:555-999-8888">Href</a> // Even this one also not working
<script>
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
alert("Inside with credentials");
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
alert("Inside without credentials");
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// Otherwise, CORS is not supported by the browser.
xhr = null;
alert("Inside without credentials CORS not supported");
}
return xhr;
}
</script>
</html>
建议我任何解决方法,如果我错了,请纠正我。但在 chrome 和 safari 中工作的正常代码相同。
解决方案
添加到您的 config.xml:
<allow-intent href="tel:*" />
然后使用:
<a href="tel:555-999-8888">Href</a>
推荐阅读
- qt - QML 中的定向阴影
- data-annotations - 将 paperjs 转换为 Coco 时消除行
- javascript - 从所有输入类型、选择等中检索值的 Javascript 通用方法
- firebase - 在 Future builder flutter firebase 中初始化 List 的问题:LateInitializationError: Field 'posts' has not been initialized
- c# - 是否可以在不单独管理 Audit_{Entity} 的情况下使用 Audit.Net?
- python - 如果一小时内的数据点少于 3 个,则删除数据
- yaml - YAML 舵图如何转义和签名
- angular - NullInjectorError:没有 InjectionToken MSAL_GUARD_CONFIG 的提供程序
- java - 冲刺启动中的多个 Excel 文件
- javascript - 如何在 oracle apex 上的我的 javascript 代码上指定 5 个 apex 项