Cocoa:点击“在 YouTube 上观看” WebView 内部不执行任何操作

发布于 2024-12-28 07:01:36 字数 858 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人哭 2025-01-04 07:01:36

“在 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 return nil from your delegate method to tell WebKit that you're disallowing the navigation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文