Cocoa:点击“在 YouTube 上观看” WebView 内部不执行任何操作
我有一个 WebView
,其中嵌入了 YouTube 视频。该视频播放正常,除了点击“在 Youtube 上观看”之外,一切都正常。
我想要“在 YouTube 上观看”按钮在默认浏览器上打开 YouTube 视频,但目前它没有执行任何操作。
我在 WebView
上设置了 WebPolicyDelegate
,但
- (void)webView:(WebView *)webView
decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
frame:(WebFrame *)frame
decisionListener:(id<WebPolicyDecisionListener>)listener`
:和:
- (void)webView:(WebView *)webView
decidePolicyForNewWindowAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
newFrameName:(NSString *)frameName
decisionListener:(id<WebPolicyDecisionListener>)listener
单击“在 YouTube 上观看”按钮时,
都不会被调用。如何检测到“在 YouTube 上观看”按钮被点击,以便我可以在默认浏览器上打开它?
I hava a WebView
with an embedded YouTube video in it. The video plays fine and everything about it works except when clicking on "Watch on Youtube".
I'd like the "Watch on YouTube" button to open the YouTube video on the default browser but currently it just doesn't do anything.
I have a WebPolicyDelegate
set on the WebView
but neither:
- (void)webView:(WebView *)webView
decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
frame:(WebFrame *)frame
decisionListener:(id<WebPolicyDecisionListener>)listener`
nor:
- (void)webView:(WebView *)webView
decidePolicyForNewWindowAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
newFrameName:(NSString *)frameName
decisionListener:(id<WebPolicyDecisionListener>)listener
are called when the "Watch on YouTube" button is clicked.
How could I detect that the "Watch on YouTube" button was clicked so I can open it on the default browser?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“在 YouTube 上观看”按钮在新选项卡/窗口中执行导航,因此您需要实现
WebUIDelegate
的-webView:createWebViewWithRequest:
方法。您必须从请求的 URL 推断该请求是否是由“在 YouTube 上观看”按钮发起的。一旦您知道了这一点,您就可以告诉默认浏览器打开 URL 并从您的委托方法返回nil
来告诉 WebKit 您不允许导航。The "Watch on YouTube" button performs its navigation in a new tab/window, so you'll need to implement
WebUIDelegate
's-webView:createWebViewWithRequest:
method. You'll have to infer from the request's URL whether the request was initiated by the "Watch on YouTube" button or not. Once you know that, you can tell the default browser to open the URL and returnnil
from your delegate method to tell WebKit that you're disallowing the navigation.