Get current URL of UIWebView

后端 未结 14 1940
天命终不由人
天命终不由人 2020-11-29 16:08

I already tried getting the current URL of my UIWebView with: webview.request.URL. Unfortunately the NSURL was empty. Anything wrong h

14条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 16:42

    I too found that the approved answer above was not reliable. But with a slight modification, it seems to work every time:

    NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"];
    

    Note the addition of ".href" to the Javascript as this is hidden at the end of the line of code.

提交回复
热议问题