如何获取我在 UIWebView 上点击的网址?

问题描述:

 NSString *testString =[NSString stringWithFormat:@" <a href = \\\\ \"www.google.com\">Google</a>"];
[webView loadHTMLString:testString baseURL:nil];

我想在

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {

if ( inType == UIWebViewNavigationTypeLinkClicked ) {
    [[UIApplication sharedApplication] openURL:inRequest.mainDocumentURL];
    return NO;
}

return YES;

}

委托方法.当我在 webview 中单击 google 超链接时,它会给出

delegate method. When I click google hyperlink in webview it gives

网址:applewebdata://

URL: applewebdata://

请帮帮我.

你的问题不是很清楚你是想获取 webview 上的tapped url 还是 webview 的加载页面 url ,

You question is not very clear if you want to get the tapped url on webview or the webview's loaded page url ,

  1. 如果你想获取 webview 加载的页面 url,你可以使用 NSURLRequestObject,类似

  1. If you want to get webview loaded page url you can use NSURLRequestObject,something like

NSString * url = [请求网址];

如果你想获得点击的链接 url ,你将不得不使用这个 java 脚本

If you want to get the clicked link url , you will have to use this java script

NSString *url = [webView stringByEvaluatingJavaScriptFromString:@window.location"];