可可WebKit / WebView委托进行位置更改? (用户点击的链接,JavaScript操作等) [英] Cocoa WebKit/WebView delegate for location change? (User clicked link, javascript action, etc)
问题描述
我已将WebView添加到Cocoa应用程序中,并且试图找出可以用来检测导航更改(用户单击链接或javascript触发更改位置等)的委托。
I have added a WebView to a Cocoa application and I'm trying to figure out which delegate I can use to detect when navigation changes (user clicks a link, or javascript fires to change the location, etc).
WebView类引用包含四个委托(WebFrameLoadDelegate协议参考,WebPolicyDelegate协议参考,WebResourceLoadDelegate协议参考和WebUIDelegate协议参考),我已经仔细研究了每个代理,但似乎找不到如何检测到这一点。我是否遗漏了一些显而易见的东西?或者没有办法得到这个东西?
The WebView class reference contains four delegates (WebFrameLoadDelegate Protocol Reference, WebPolicyDelegate Protocol Reference, WebResourceLoadDelegate Protocol Reference and WebUIDelegate Protocol Reference) and I have looked at each of these, but I cannot seem to find how to detect this. Am I missing something blatantly obvious or is there no way to get this?
tldr-试图弄清楚如何设置一个委托来在WebView出现时获取事件。更改网址。 (特别是我需要知道新的URL是什么。)
tldr - Trying to figure out how I can set a delegate to get an event when the WebView is changing URL. (Specifically I need to know what the new URL is).
推荐答案
使用WebKit(例如MacOS X)可能是最好的选择跟踪请求位于 webView:identifierForInitialRequest:fromDataSource:
中,尽管 webView:resource:willSendRequest:redirectResponse:fromDataSource:
是也很好,并且具有允许您修改请求的优点。
Using WebKit (i.e. MacOS X) then probably the best place to track requests is in webView:identifierForInitialRequest:fromDataSource:
, although webView:resource:willSendRequest:redirectResponse:fromDataSource:
is also good, and has the advantage of allowing you to modify the request.
与iOS一样,您可以使用 [请求URL]
。
As with iOS, you can use [request URL]
.
通过 [webView setResourceLoadDelegate:self];
进行设置。
资源负载委托(如我认为,上述方法比政策委托方法提供了更好的选项来处理请求。
The resource load delegate (as above) gives better options to handle the request, in my opinion, than the policy delegate methods.
这篇关于可可WebKit / WebView委托进行位置更改? (用户点击的链接,JavaScript操作等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!