【发布时间】:2018-10-10 14:27:43
【问题描述】:
如果我们从 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 中使用相同的正常代码。
【问题讨论】:
标签: javascript android ionic-framework mobile