在我的WebView中,当用户点击webview中的链接时,该属性在哪里?我查看了文档并尝试了类似
的内容[webView.request.URL description]
webView.request.URL.absoluteURL or absoluteString
,一切都是空白的。谢谢!
答案 0 :(得分: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
}
希望这会对你有所帮助。
答案 1 :(得分:0)
也许试试这个:
NSString *link = [webView.request.URL absoluteString];
希望这有帮助!
答案 2 :(得分:0)
当用户点击任何链接
时,您需要捕获webview委托功能- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { NSURL *url = [request URL]; NSString *link = [url absoluteString]; return YES; }