【问题标题】:Flutter webview_flutter: Not able to detect platform with java-script codeFlutter webview_flutter:无法使用 java 脚本代码检测平台
【发布时间】:2021-03-25 19:19:17
【问题描述】:

我正在使用 webview_flutter 来显示网页。我正在使用下面的代码来检测平台,比如它是 android 还是 ios。我下面的代码不起作用。 Flutter webview - https://pub.dev/packages/webview_flutter 我在正文中添加了以下类。

class - view-withKeyboard


function applyAfterResize() {
            console.log(getMobileOperatingSystem());
            if (getMobileOperatingSystem() == 'ios') {
                if (originalPotion !== false) {
                    var wasWithKeyboard = $('body').hasClass('view-withKeyboard');
                    var nowWithKeyboard = false;
                        var diff = Math.abs(originalPotion - ($(window).width() + $(window).height()));
                        if (diff > 100) nowWithKeyboard = true;
                    $('body').toggleClass('view-withKeyboard', nowWithKeyboard);
                    if (wasWithKeyboard != nowWithKeyboard) {
                        //onKeyboardOnOff(nowWithKeyboard);
                    }
                }
            }
        }
        $(document).on('focus blur', '.white-div input[type=text]', function(e){
            //alert('here');
            if (getMobileOperatingSystem() == 'ios') {
              var $obj = $(this);
              var nowWithKeyboard = (e.type == 'focusin');
              $('body').toggleClass('view-withKeyboard', nowWithKeyboard);
              onKeyboardOnOff(nowWithKeyboard);
            }
        });

【问题讨论】:

  • 您能否向我们展示一下您如何使用 WebView 小部件。

标签: javascript html css flutter


【解决方案1】:

先启用JavascriptMOde,然后使用evaluateJavascript

WebView(
    javascriptMode: JavascriptMode.unrestricted,
    initialUrl: '',
    onWebViewCreated:
        (WebViewController webViewController) async {
      webViewController.evaluateJavascript(
          "javascript:(function() { " +
              "console.log('Test Test Test');" +
              "})()");
    },
  ),

【讨论】:

    猜你喜欢
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 2013-06-22
    • 2011-04-06
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    相关资源
    最近更新 更多