如果“display:none”,则不会在android webview中打开文件选择器对话框

前端之家收集整理的这篇文章主要介绍了如果“display:none”,则不会在android webview中打开文件选择器对话框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
早上好开发者

好吧,我已经制作了一个android webview应用程序,我面临一个小问题,我搜索了很多,但找不到任何有效的解决方案.

好.问题是.我有这样的PHP / Html代码

<input type="file" name="banner_image" style="display:none;" id="banner_image" onChange="fileSelected('banner');" accept="image/*" />

注意:style =“display:none;”

我通过像这样的Jquery从div的onClick调用输入字段的onclick事件

<div class="profile-pic-txt" onClick="openFileDialog('profile');"> Click here to add
        Profile Picture
        <p>200px/200px</p>
      </div>

这是我的java脚本openFileDialog()函数

function openFileDialog(test)
{
$("#banner_image").click();
console.log("Test");
}

它没有打开我的文件选择器对话框.

但当我删除显示:无;从我上面的代码它只是工作正常.我在iPhone中测试了它在两种情况下的工作正常,但在android webview中它没有调用我的文件选择器对话框,同时保持display:none.


我必须使我的浏览按钮在我的网页上不可见,因为它的模板/设计要求(我用display:none完成)

在最后这里是我的android webview配置代码.

private void configureWebview() {

    webView.getSettings().setDefaultZoom(ZoomDensity.FAR);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setLoadWithOverviewmode(true);
    webView.getSettings().setCacheMode(MODE_APPEND);
    webView.getSettings().setUseWideViewPort(true);

    webView.getSettings().setRenderPriority(RenderPriority.HIGH);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    webView.setWebViewClient(new MyWebViewClient());

    webView.setWebChromeClient(new WebChromeClient() {

        @Override
        public boolean onConsoleMessage(ConsoleMessage cm) {

            Log.e("Console Webview",cm.message() + " -- From line " + cm.lineNumber()
                            + " of " + cm.sourceId());

            return true;

        }

        // For Android < 3.0
        @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            uploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("image/*");
            MainActivity.this.startActivityForResult(
                    Intent.createChooser(i,"File Chooser"),FILECHOOSER_RESULTCODE);
        }

        // For Android 3.0+
        @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg,String acceptType) {
            uploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("image/*");
            MainActivity.this.startActivityForResult(
                    Intent.createChooser(i,"File Browser"),FILECHOOSER_RESULTCODE);
        }

        // For Android 4.1
        @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg,String acceptType,String capture) {
            uploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("image/*");
            MainActivity.this.startActivityForResult(
                    Intent.createChooser(i,MainActivity.FILECHOOSER_RESULTCODE);
        }

    });

}

只是重复我的问题:在< input name =“banner_image”style =“display:none;”中保持display:none时,文件选择器没有打开id =“banner_image”onChange =“fileSelected('banner');” type =“file”accept =“image / *”/>

解决方法

如果使用display:none,则输入文件不起作用

只是把它放在可视区域之外,例如位置:绝对;左:-500px;

猜你在找的CSS相关文章