【发布时间】: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