本文介绍了如何从 UIWebView 获取 URL 的哈希片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我正在尝试在 UIWebView 中加载 URL 的哈希片段,我尝试了不同的方法,但它似乎不起作用.
I'm trying to get hash fragment of URL loaded in UIWebView, I have tried different approaches it does not seem to work.
例如,如果 UIWebView 加载了http://www.mysite.com/home#main":
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];
然后我想获取完整的网址,但它只返回http://www.mysite.com/home",有 3 种不同的方法:
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"];
我错过了什么
推荐答案
试试 NSString *fragment = [webView.request.URL fragment];
这篇关于如何从 UIWebView 获取 URL 的哈希片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)