2011-02-24 90 views
0

我必须使用javascript stringbyevaluatingstring显示UIWebView内容。iphone uiwebview超链接

在我的项目中,超链接不起作用。如何启用UIWebView中的所有链接?

有人知道的话请给出一段样片代码或想法。

+0

你可以发布你正在使用的代码吗?你的问题非常模糊。 – TNC 2011-02-24 06:35:28

回答

1

只是一个样本尝试:在UIViewController中

谁“拥有”你的UIWebView命名为:“yourWebView”

// navigate to a new html file: 
[yourWebView stringByEvaluatingJavaScriptFromString:@"document.location='aNewHtmlFile.html'"]; 

// show a normal javascript alert window with a message: 
[yourWebView stringByEvaluatingJavaScriptFromString:@"alert('This is what an alert message looks like.');"]; 

// ask to the html file its own title: 
NSString *appS = [yourWebView stringByEvaluatingJavaScriptFromString:@"document.title"]; 
NSLogg(@"the title is: %@", appS); 

// call a personal JS in your html document: 
[yourWebView stringByEvaluatingJavaScriptFromString:@"callMyJSFunctionToshowMyAlert('Hallo!');"]; 
// whit this in your html file: 
    <head> 
... 
    <script> 
    function callMyJSFunctionToshowMyAlert(aMsg) { 
     alert(aMsg); 
    } 
    </script> 
... 
    </head> 

如果一些funcs中的不那么工程可能存在一定的误差当你实例化你的UIWebView加载html文件的地方。 但是你在找什么?

+0

谢谢,这对我非常有用。抱歉迟来的谢谢。 。 – suresh 2011-08-19 10:05:16

0

您是否设置了UIWebView的属性 - 检测链接?

+0

没有如何设置请帮助我... – suresh 2011-02-28 05:38:47

+0

在IB for web查看属性中,您可以设置Web链接的检测。 – Viraj 2011-02-28 06:00:10