如何获取我在 UIWebView 上点击的网址? [英] How to get url which I hit on UIWebView?
本文介绍了如何获取我在 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 ,
如果你想获取 webview 加载的页面 url,你可以使用 NSURLRequestObject,类似
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"];
这篇关于如何获取我在 UIWebView 上点击的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文