【问题标题】:How to add CORS through JS while opening tel:XXXXXXXXXX打开tel:XXXXXXXXXX时如何通过JS添加CORS
【发布时间】: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


    【解决方案1】:

    添加到您的 config.xml:

    <allow-intent href="tel:*" />
    

    然后使用:

    <a href="tel:555-999-8888">Href</a>
    

    【讨论】:

    • 我们可以在哪里获得这个 config.xml。通常在 web J2EE 项目中,我们有 web.xml
    猜你喜欢
    • 1970-01-01
    • 2021-06-04
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多