gpt4 book ai didi

ios - 如何从 UIWebView 获取 URL 的哈希片段

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:18:50 26 4
gpt4 key购买 nike

我正在尝试获取加载到 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];

然后我想获取完整的 url,但它仅通过 3 种不同的方法返回“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"];

我错过了什么

最佳答案

试试 NSString *fragment = [webView.request.URL fragment];

关于ios - 如何从 UIWebView 获取 URL 的哈希片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6408082/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com