繁体   English   中英

打开tel:XXXXXXXXXX时如何通过JS添加CORS

[英]How to add CORS through JS while opening tel:XXXXXXXXXX

如果我们从Android移动版进行访问,我需要通过Java Script打开本机拨号程序。 由于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>

暂无
暂无

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

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