使用UIWebview的当前url更新地址栏

时间:2022-08-14 18:05:06

Like iPhone safari browser, I want to update UItextview with current url of UIWebView

和iPhone safari浏览器一样,我想用UIWebView的当前url更新UItextview

I tried shouldStartLoadWithRequest delegate method, but I end up with url of some ads/iframe

我尝试了shouldStartLoadWithRequest委托方法,但最终得到了一些ad /iframe的url

If I use webViewDidFinishLoad delegate method, then address bar gets updated at the end of the request.

如果我使用webViewDidFinishLoad委托方法,那么地址栏将在请求结束时更新。

Please help me on the best approach.

请帮助我最好的方法。

2 个解决方案

#1


5  

You want to use the mainDocumentURL method on the NSURLRequest in webView:shouldStartLoadWithRequest:. This should contain the main document URL regardless of whether the page is loading or a resource on the page (e.g. a frame) is loading.

您希望在webView:shouldStartLoadWithRequest:中的NSURLRequest上使用mainDocumentURL方法。它应该包含主文档URL,不管页面是正在加载还是正在加载页面上的资源(例如框架)。

#2


0  

Use webviewDidFinishLoad when delegated from your webview, and then query it for the title with [webview stringByEvaluatingJavaScriptFromString:@"document.title"] or weboutWebView.request.URL.absoluteString for the url.

使用webviewDidFinishLoad当从webview委派时,然后用[webview stringByEvaluatingJavaScriptFromString:@“文档”查询标题。标题”)或weboutWebView.request.URL。absoluteString url。

#1


5  

You want to use the mainDocumentURL method on the NSURLRequest in webView:shouldStartLoadWithRequest:. This should contain the main document URL regardless of whether the page is loading or a resource on the page (e.g. a frame) is loading.

您希望在webView:shouldStartLoadWithRequest:中的NSURLRequest上使用mainDocumentURL方法。它应该包含主文档URL,不管页面是正在加载还是正在加载页面上的资源(例如框架)。

#2


0  

Use webviewDidFinishLoad when delegated from your webview, and then query it for the title with [webview stringByEvaluatingJavaScriptFromString:@"document.title"] or weboutWebView.request.URL.absoluteString for the url.

使用webviewDidFinishLoad当从webview委派时,然后用[webview stringByEvaluatingJavaScriptFromString:@“文档”查询标题。标题”)或weboutWebView.request.URL。absoluteString url。