在iPhone网络应用程序内部打开一些链接,在外部打开其他链接

Open some links inside iPhone web app others outside

本文关键字:链接 外部 其他 iPhone 应用程序 网络 内部      更新时间:2023-09-26

我正在为iOS设备开发一个web应用程序。我知道,通过使用以下代码,我可以在我的网络应用程序中打开我的网站应用程序的链接。

var a=document.getElementsByTagName("a");
for(var i=0;i<a.length;i++)
{
    a[i].onclick=function()
    {
        window.location=this.getAttribute("href");
        return false
    }
}

现在我有以下问题,我想在我的网络应用程序之外打开多个链接,例如"短信:1-23-456"。有没有人知道一种方法,可以让一些链接在我的网络应用程序外打开,但仍然可以打开应用程序内的其余链接?

我认为没有标准的方法可以做到这一点。您可以将自定义属性添加到锚点标记中,如以下

<a hfre="www.example.com" openExternally="yes">Test</a>

然后在代码中检查该属性

if(a[i].openExternally="yes") {
    return true;
} else {
    window.location=this.getAttribute("href");
    return false;
}

希望这能有所帮助。

只需检查URL方案:

var url =this.getAttribute("href")
If(url.startsWith("http")) {
  window.location = url;
  return false;
}
Else {
  return true;
}