【问题标题】:Open some links inside iPhone web app others outside在 iPhone 网络应用程序内打开一些链接,其他在外部
【发布时间】:2012-03-21 17:24:41
【问题描述】:

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

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”。有没有人知道如何让一些链接在我的网络应用程序之外打开,并且仍然能够在应用程序内部打开其余链接?

【问题讨论】:

标签: javascript iphone ios web-applications hyperlink


【解决方案1】:

我认为没有标准的方法可以做到这一点。您可以像这样向锚标记添加自定义属性

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

然后在代码中检查该属性

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

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    只需检查 URL 方案:

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

    【讨论】:

      猜你喜欢
      • 2017-09-27
      • 2012-05-13
      • 1970-01-01
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多