简体   繁体   English

隐藏文件类型的文件上传,通过jquery提交表单

[英]file upload with file type hidden, submitting form through jquery

I am using iframe for file uploading and is working fine in all browsers except IE. 我正在使用iframe进行文件上传,并且在IE以外的所有浏览器中都能正常工作。 It says access denied on form.submit line. 它说在form.submit行上拒绝访问。 Please check my code below. 请在下面检查我的代码。

$(function(){
        $('.uploadBanner').click(function () {
               $('.uploadFile').trigger('click');
            });
        $(".uploadFile").on('change', function(e){  
            e.preventDefault();            
            document.getElementById('bannerUploadForm').submit();
        });  

    });

where my .uploadBanner is the click event for hidden field and .uploadFile is the hidden file type 我的.uploadBanner是隐藏字段的click事件,.uploadFile是隐藏文件类型

let me know on this. 让我知道这一点。

IE doesn't allow manipulation of the type="file" input element from javascript due to security reasons. 出于安全原因,IE不允许通过javascript操作type =“ file”输入元素。

You can do a work around for this issue be detecting if the browser is ie open a file upload dialog and let the user to click on it manually 您可以解决此问题,方法是检测浏览器是否打开, ie打开文件上传对话框,然后让用户手动单击它

if(jQuery.browser.msie) { 
    $('#hiddenUploadForm').dialog();
}
else {
    $('.uploadFile').click();
}

IE explicitly prohibits you from programmatically opening up the file chooser dialog (by triggering a click event) and then programmatically uploading any of the selected files. IE明确禁止您以编程方式打开文件选择器对话框(通过触发click事件),然后以编程方式上载任何选定的文件。 The error will occur when you attempt to submit the form in this case. 在这种情况下,当您尝试提交表单时将发生错误。 Let the user click the file input element instead and you will be fine. 让用户单击文件输入元素,就可以了。 If you need to style the file input element, it's not hard to do this. 如果您需要设置文件输入元素的样式,这并不难。 Simply make it opaque and add make it the child of a div that contains the proper styling. 只需使其不透明并添加使其成为包含正确样式的div的子代即可。 Look around on SO or Google for specifics if needed. 如有需要,请查看SO或Google的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM