让 WebView 的行为与 Safari 完全相同

发布于 2024-10-06 06:44:27 字数 197 浏览 4 评论 0原文

(经过编辑以更好地描述我给出的答案)

我在 InterfaceBuilder 中创建了一个非常简单的浏览器,由导航栏和网页视图组成。

一切工作正常,除了当我尝试在网络视图的输入字段之间切换时,焦点转到导航栏。

我假设我需要对响应者链做一些事情,但我一直无法弄清楚做什么。

有什么建议吗?

谢谢, 凯莉

(edited to give a better description of the answer I gave)

I have created a very simple browser in InterfaceBuilder consisting of a nav bar and a webview.

Everything works fine except when I try to tab between input fields is the webview, the focus goes to the nav bar.

I'm assuming I need to do something with the responder chain, but I haven't been able to figure out what.

Any advice?

Thanks,
Kelly

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

情未る 2024-10-13 06:44:27

世界上可能没有其他人关心这个问题,但我会回答它,以防有人在某个时候需要这个。

正如我在评论中提到的,我正在使用卡布奇诺框架,但实际上我遇到了 3 个不同的问题。

让我给你介绍一下这里的设置。

我正在创建一个嵌入 WebView 的可可应用程序,并加载一个包含卡布奇诺应用程序的页面。起初,字段之间的选项卡对于任何网页上的任何表单都不太有效。

  1. 正如我在评论中所说,如果您使用IB,您可以将窗口“initialFirstResponder”设置为webview,并且至少“正常”表单可以正常工作。卡布奇诺仍然没有。
  2. 第二个问题是 dom 事件中的 keyCode 和 charCode 与 cocoa 和 Safari 中的 WebView 不同。事实证明,有一种叫做“键盘怪癖”模式的东西。如果您在中查找 _needsKeyboardEventDisambiguationQuirks
    WebView ObjC 类源
    你会看到它对 Safari 进行了例外处理,将其关闭。它应该为旧版本的 WebKit 关闭它,但事实并非如此。请参阅 webkit 错误 32694
    为了解决这个问题,我必须做两件不同的事情。
    a) 覆盖 _needsKeyboardEventDisambiguationQuirks 使其返回 NO
    b) 如果在重写该方法时 WebView 已实例化,则还需要调用 [[webviewinstancepreferences] _postPreferencesChangesNotification] 才能使其正常工作。
    然后,这会使您的 WebView 像 Safari 一样发送 DOM 事件。

  3. 最后,cappuccino 查看用户代理字符串以确定如何处理某些内容。它正在检查 WebKit 和 Safari。我抄写了 safari 用户代理字符串并将其设置为 WebView 的自定义用户代理字符串。

    [mywebviewinstance setCustomUserAgent: @"Mozilla/5.0(Macintosh;U;Intel Mac OS X 10_6_6;en-us)AppleWebKit/533.19.4(KHTML,如 Gecko)版本/5.0.3 Safari/533.19。 4"]
    

最后,一切都像在 Safari 中一样进行。

希望这对某人有帮助!

There is probably no one else in the world who cares about this, but I'm going to answer it in case someone needs this at some point.

As I mentioned in the comments, I am using the cappuccino framework and I was actually having 3 different problems.

Let me give you the set up here.

I was creating a cocoa app with a WebView embedded and loading a page with a cappuccino app in it. At first tabbing between fields didn't quite work for any form on any webpage.

  1. As I said in the comments, if you are using IB, you can set the windows 'initialFirstResponder' to be the webview, and at least 'normal' forms work correctly. Cappuccino still did not.
  2. Second was the problem where keyCode and charCode in the dom event was different from WebView in cocoa to Safari. It turns out that there is something called 'keyboard quirks' mode. If you look for _needsKeyboardEventDisambiguationQuirks in the
    WebView ObjC class source
    you will see that it makes an exception for safari, turning it off. It is supposed to turn it off for older versions of WebKit, but it doesn't. see webkit bug 32694
    To solve this, I had to do two different things.
    a) override _needsKeyboardEventDisambiguationQuirks so that it returns NO
    b) if the WebView is already instantiated when you override that method, you will need to also call [[webviewinstance preferences] _postPreferencesChangesNotification] in order to get it to work.
    This then makes your WebView send the DOM Events like Safari.

  3. Finally, cappuccino was looking at the user agent string to determine how to handle some stuff. It was checking for WebKit and for Safari. I cribbed the safari user agent string and set that as a custom user agent string for the WebView.

    [mywebviewinstance setCustomUserAgent: @"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-us) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4"]
    

Finally, everything worked just like it did in safari.

Hope this helps someone!

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