【问题标题】:Unable to write in input tag in Xamarin MacOs Webview within a iframe无法在 iframe 内的 Xamarin MacOs Webview 中写入输入标记
【发布时间】:2022-10-05 20:24:46
【问题描述】:

我们有一个 Xamarin MacOs 应用程序,它使用 webview 来显示 web 内容。

显示的第一页是本地 html 页面文本。该页面有一个 iframe,指向一个允许像 vimeo 一样嵌入的外部网络。

如果该 iframe 具有类型为 \"text\" 的输入并尝试在其中写入,则不会触发 keypress/keydown,然后不会在输入内写入任何文本。

已扩展 WebKit.WebView 以访问本机属性,但没有找到任何允许这样做的偏好。

Xamarin Forms 使用的版本是 5.0.0.2196

对于这种奇怪的情况有什么解决方法吗? 发送

更新 1

如果按“Control+tab”键,则输入开始接收输入键。所以,问题是 iframe 中的控件有焦点,但 webview 中的 iframe 没有。

    标签: xamarin webview


    【解决方案1】:

    您需要检测 iframe 中的任何 keyup 事件。以下是HTML & JS 代码 sn-ps 供您参考:

    HTML:

    <iframe id='this-iframe'></iframe>
    

    JS:

    var iframe_content = '<html><body><input type="text" id="input_id"/><span id="result"></span></body></html>';
    var doc = document.getElementById('this-iframe').contentWindow.document;
            doc.open();
            doc.write(iframe_content);
            doc.close();    
        
    $(document.getElementById('this-iframe').contentWindow.document).keyup(function(e){
       if($('#this-iframe').contents().find('#input_id').is(":focus")){
          $('#this-iframe').contents().find("#result").html($('#this-iframe').contents().find('#input_id').val());
       }       
    });
    

    【讨论】:

    • Tx 为您提供帮助,但在 webview 的 iframe 内没有触发任何按键。就像 MacOs 的 webview 会阻止那些在 webview 主页面中工作的事件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    • 2012-06-25
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多