Ios 如何获取我在UIWebView上找到的url?
} 委托方法。 当我在webview中单击google超链接时,它会显示 URL:applewebdata://Ios 如何获取我在UIWebView上找到的url?,ios,objective-c,uiwebview,Ios,Objective C,Uiwebview,} 委托方法。 当我在webview中单击google超链接时,它会显示 URL:applewebdata:// 请帮助我。您已经有了NSURLRequest对象。从那个访问url -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType { if ( inType == UIWebV
请帮助我。您已经有了NSURLRequest对象。从那个访问url
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:inRequest.mainDocumentURL];
return NO;
}
return YES;
方式1:
inRequest.URL
方式2:
NSString *currentURL = myWebView.request.URL.absoluteString;
}
请让我知道它是否有效。谢谢如果您想在webview上获取点击的url或webview加载的页面url,您的问题不是很清楚
NSString*url=[请求url]代码>
NSString*url=[webView stringByEvaluatingJavaScriptFromString:@“window.location”]代码>
你可以这样做
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
//CAPTURE USER LINK-CLICK.
NSURL *url = [request URL];
yourTextBox.text = [url absoluteString];
return YES;
对于Swift:
webUrlLabel.text = webView.request.URL.absoluteString
无论何时加载您的网页,您都可以使用它,在这种情况下,我将其用作标签:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([request.URL.absoluteString rangeOfString:@"www.google.com"].location!=NSNotFound)
{
[[UIApplication sharedApplication]openURL:request.URL];
return NO;
}
return YES;
}
对于目标C:
webUrlLabel.text = webView.request.URL.absoluteString
weburlabel
是一个UILabel
webView
是我的UIWebView我打印了它。我打印[url absoluteString]时,它以方式2给出“applewebdata://”,它给出“applewebdata://”我想要第二个,但我打印url。url给出“”。在点击事件中,您是如何使用它的?只是为了确保webview交互已启用。我正在动态创建uiwebview并设置其委托。您可以在此方法中尝试以下代码—(BOOL)webview:(uiwebview*)webview shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType;NSString url=[webView stringByEvaluatingJavaScriptFromString:@“window.location”];将此代码放入此-(BOOL)webView:(UIWebView)webView shouldStartLoadWithRequest:(NSURLRequest*)请求导航类型:(UIWebView导航类型)导航类型;根据它应该是webView.request.URL.absoluteString
,老实说,我在问自己是否错了。我做得不太快,但据我所知,这一点并没有改变,所以我不得不先做一些搜索。
NSString *currentPage = [NSString stringWithFormat:@"%@", webView.request.URL.absoluteString];