2011-02-24 85 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