How to get hash fragment of URL from UIWebView

后端 未结 4 986
走了就别回头了
走了就别回头了 2021-01-15 16:22

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

相关标签:
4条回答
  • 2021-01-15 17:07

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

    0 讨论(0)
  • 2021-01-15 17:14

    Use the following code snippet
    NSLog(@"Hash fragment :%@",[NSString stringWithFormat:@"%@",webview.request.URL.fragment]);

    0 讨论(0)
  • 2021-01-15 17:17

    [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......

    0 讨论(0)
  • 2021-01-15 17:26

    I think you should check that, request.url.absolutestring has fragment on shouldStartLoadWithRequest, webViewDidFinishLoad.

    0 讨论(0)
提交回复
热议问题