提交表单按钮在WebView上不起作用 [英] Submit form button does not work on WebView

查看:156
本文介绍了提交表单按钮在WebView上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WebView中加载某些网站时,我无法提交其表单.单击提交输入(按钮)时,它会集中显示,但没有其他反应.

When loading some websites in a WebView, I am not able to submit their forms. When clicking the submit input (button), it gets focused, but nothing else happens.

这些相同的网站可以在Chrome(在同一设备上)上运行.

Those same sites work on Chrome (in the same device).

我该如何解决?我是否缺少设置?

也很感谢对此问题发生原因的反馈.


复制步骤

  1. 加载 BrowseActivity ,它将加载https://m.ebay.com/
  2. 页面加载后,输入搜索查询(例如笔记本电脑")
  3. 按下表单的蓝色搜索按钮或软件键盘上的操作按钮(放大镜玻璃图标)
  1. Load BrowseActivity, which will load https://m.ebay.com/
  2. Once the page loads, enter a search query (e.g. "Laptop")
  3. Press the form's blue search button or the action button of the software keyboard (magnifier glass icon)

预期的行为:应提交搜索表单并显示搜索结果

Expected behavior: The search form should be submitted and the search results shown

实际行为:蓝色的搜索按钮获得了焦点(以亮边框表示),但没有其他反应.

Actual behaviour: The blue search button gets focus (represented by a bright border), but nothing else happens.


BrowseActivity.java

public class BrowseActivity extends AppCompatActivity {

    WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browse);

        mWebView = (WebView) findViewById(R.id.home_wv_content);
        mWebView.setWebViewClient(new WebViewClient());
        mWebView.setWebChromeClient(new WebChromeClient());
        mWebView.getSettings().setJavaScriptEnabled(true);

        // Ebay has a blue search button where this issue can be replicated
        mWebView.loadUrl("https://m.ebay.com");
    }
}

activity_browse.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="my.example.BrowseActivity">

    <WebView
        android:id="@+id/home_wv_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</android.support.constraint.ConstraintLayout>

我已经考虑过使用自定义的 JavaScript接口单击该按钮,读取输入的查询,然后重定向到搜索页面.

I have considered using a custom JavaScript interface in order to catch the click on the button, read the input query and then redirect to the search page.

无论如何,这种方法与网站本身(例如ebay)紧密相关,我希望它可以与其他网站一起使用.另外,我不希望网站上的更改破坏我的申请.

Anyway, this approach is tightly coupled to the website itself (e.g. ebay) and I'd like this to work with different sites. Also, I don't want changes in the website to break my application.

推荐答案

您可能需要启用Webview中的其他功能才能具有与浏览器完全相同的功能.默认情况下,除JavaScript外,webview中还有其他禁用的东西.

You may need to enable other things in webview to have full equivalent of a browser. There are other things that are disabled by default in webview in addition to javascript).

尝试此设置(基于我的项目,我们确实对Webview遇到了一些问题):

Try this setting (based on my project where we did have some problems with webview):

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setDatabasePath(dbpath); //check the documentation for info about dbpath
mWebView.getSettings().setMinimumFontSize(1);
mWebView.getSettings().setMinimumLogicalFontSize(1);

这篇关于提交表单按钮在WebView上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆