【问题标题】:Disable link in UIWebView in appearance and function在外观和功能上禁用 UIWebView 中的链接
【发布时间】:2010-12-22 14:51:39
【问题描述】:

我希望禁用 UIWebView 上的 href 链接。首先,我希望改变链接的外观,这样用户就不会认为它是可点击的。其次,我希望无法点击实际链接。我不想尝试webView:shouldStartLoadWithRequest:navigationType:,因为那不会改变我的链接的外观。

我找到了这个答案: Disabling visible links in UIWebView

但上述方法对我不起作用。这是我的代码:

NSString* s=[[NSString alloc] initWithFormat:@"for (a in document.getElementsByTagName(\"a\")) {a.href = \"\";}"];
[myWebView stringByEvaluatingJavaScriptFromString:s];

我已经为此工作了几个小时,感谢任何建议!谢谢!

更新:

我尝试了以下javascript,但仍然无法正常工作

for(link in document.getElementsByTagName("a")) {
        var span = document.createElement("span");
        var txt = link.href;
        var textNode= document.createTextNode(txt);
        span.appendChild(textNode);
        if(link!=undefined){
            link.parentNode.replaceChild(span, link);
        }
}

【问题讨论】:

    标签: iphone cocoa-touch ios4


    【解决方案1】:

    提供的代码只会使链接没有目的地,但它仍然看起来像一个链接。

    我会使用相同的概念,但使用 answer 中的 javascript,它基本上将 href 转换为 span,因此它只显示为文本。

    【讨论】:

    • 谢谢!嗯..我尝试了以下方法,但没有成功: for(link in document.getElementsByTagName("a")) { var span = document.createElement("span"); var txt = 链接.href; var textNode=document.createTextNode(txt); span.appendChild(textNode); if(link!=undefined){ link.parentNode.replaceChild(span, link); } }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 2012-02-15
    • 1970-01-01
    相关资源
    最近更新 更多