简体   繁体   English

获取可可的WebView的当前URL

[英]Get the current URL of Cocoa's WebView

Im new to Cocoa.我是 Cocoa 的新手。

I'm trying to extract the URL of the currently loaded webpage in my WebView object.我正在尝试在我的 WebView object 中提取当前加载的网页的 URL。 I use this WebView to show a login screen and after logging in I have to get some parts of the URL.我使用这个 WebView 显示登录屏幕,登录后我必须获取 URL 的某些部分。

I have already tried我已经试过了

[[[[frame provisionalDataSource] request] URL] absoluteString];

but this one only works one time, when called while loading.但是这个只能工作一次,在加载时调用。 If the loading is complete it returns "(null)".如果加载完成,则返回“(null)”。 The problem is, that it seems like the URL changes while loading the page so i get the wrong URL.问题是,似乎 URL 在加载页面时发生了变化,所以我得到了错误的 URL。

Does anybody know how to get the URL at any time I want?有人知道如何随时获得 URL 吗?

Thanks谢谢

Switch provisionalDataSource with dataSource .dataSource切换provisionalDataSource数据源。 Once the frame starts loading, it's not provisional anymore.一旦框架开始加载,它就不再是临时的了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM