【问题标题】:Capture onTap on Webview and send the details在 Webview 上捕获 onTap 并发送详细信息
【发布时间】:2021-06-20 21:10:31
【问题描述】:

是否可以从 webView 获取点击事件,或者如果他的 url 发生更改,我如何获取当前的 url。或者当 url 改变时需要重新加载 webview。

注意:不在按钮点击动作中

 Stack(
            children: [
    
    
              WebView(
                javascriptMode: JavascriptMode.unrestricted,
                initialUrl: mainUrl,
                onWebViewCreated: (WebViewController webViewController){
                  _controller.complete(webViewController);
                },
                onPageFinished: (url){
                  allJsfile();
    
                },
                
              ),
              GestureDetector(
    
                onTapDown: (_) => print('webview onTapDown $_'),
                onTapUp: (_) => print('webview onTapUp $_'),
                onTap: () => print('webview onTap'),
                child: Container(),
              ),
            ],
          ),

【问题讨论】:

  • 嗨!您想在 GestureDetector 的 onTap 处理程序中获取当前 url,对吗?
  • 是的。如果用户单击 webview 导航到其他页面,我想获取 url 然后我想要 url

标签: android ios flutter android-studio


【解决方案1】:

您可以通过这种方式获得它。 只需在 Webview 中使用“navigationDelegate”方法即可。

              WebView(
                  initialUrl: provider.webUrl,
                  javascriptMode: JavascriptMode.unrestricted,
                  navigationDelegate: (action) {
                    if (action.url ==
                        "https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f") {
                      return NavigationDecision.prevent;
                    } else {
                      return NavigationDecision.navigate;
                    }
                  },
                  debuggingEnabled: true,
                  gestureNavigationEnabled: true,
                )

如果您想浏览所有类型的页面,请使用

navigationDelegate: (NavigationRequest action) {
   return NavigationDecision.navigate;
}

你可以得到导航网址

navigationDelegate: (action) {
  print(action.url);
}

【讨论】:

    猜你喜欢
    • 2018-01-28
    • 1970-01-01
    • 2014-01-24
    • 2011-04-24
    • 2020-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多