如何从UIWebView获取URL的哈希片段 [英] How to get hash fragment of URL from UIWebView
问题描述
我试图获得在UIWebView中加载的URL的哈希片段,我尝试了不同的方法,它似乎不工作。
例如,如果UIWebView加载了http://www.mysite.com/home#main:
NSURL * url = [NSURL URLWithString:@http://www.mysite.com/home#main];
NSURLRequest * request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
然后我想获取完整的网址,但它只返回http://www.mysite .com / home有三种不同的方法:
<1>
NSString * currentURL = [webView.request.URL absoluteString];
<2>
NSString * currentURL = [NSString stringWithFormat:@%@,[[webView request] URL]];
<3>
NSString * currentURL = [webView stringByEvaluatingJavaScriptFromString:@window.location.hash];
我缺少什么
我在方法1上失败并且接近2
可能您的代码在其他方面有错误......I'm trying to get hash fragment of URL loaded in UIWebView, I have tried different approaches it does not seem to work.
For example if the UIWebView is loaded with "http://www.mysite.com/home#main":
NSURL *url = [NSURL URLWithString:@"http://www.mysite.com/home#main"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
then I want to get the full url, but it only return "http://www.mysite.com/home" with 3 different approaches:
1:
NSString *currentURL = [webView.request.URL absoluteString];
2:
NSString *currentURL = [NSString stringWithFormat:@"%@",[[webView request] URL]];
3:
NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.hash"];
what am I missing
[webview stringByEvaluatingJavaScriptFromString:@"window.location.hash"]
is the only way I had success to get the hash fragment in my case
I failed on approaches 1 and approaches 2
maybe your code wrong on someway else......
这篇关于如何从UIWebView获取URL的哈希片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!