2012-07-09 105 views
0

在我的WebView中,當用戶點擊webview中的鏈接時,該屬性在哪裏?我看了看文檔,並嘗試過像如何獲取UIWebView加載的網址?

[webView.request.URL description] 
webView.request.URL.absoluteURL or absoluteString 

,一切都是空白的。謝謝!

+4

使用搜索功能:http://stackoverflow.com/questions/4679378/iphone-uiwebview-get-the-url-of-the-link-clicked – lm2s 2012-07-09 21:32:19

回答

0

也許試試這個:

NSString *link = [webView.request.URL absoluteString]; 

希望這有助於!

0

你需要捕捉的WebView委託功能,當任何一個環節

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { 
    NSURL *url = [request URL]; 
    NSString *link = [url absoluteString]; 
    return YES; 
} 
3

用戶水龍頭實施委託功能像

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
    if(navigationType == UIWebViewNavigationTypeLinkClicked) 
    { 
     // Its following the click on some link on the loaded webpage 
     NSString *strLink = [[request URL] absoluteString]; // Clicked Link URL 
    } 
    return YES; // return YES if you allow the page to load else return NO 
} 

希望這有助於你。