首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在IE 9中,plupload似乎不能上传文件。它可以在其他浏览器中工作

在IE 9中,plupload似乎不能上传文件。它可以在其他浏览器中工作
EN

Stack Overflow用户
提问于 2014-01-09 15:57:34
回答 3查看 4.7K关注 0票数 5

在我们的项目中,我们使用plupload上传单个excel文件。这在除IE9之外的所有浏览器中都有效。单击“上载”链接将显示文件对话框,但在尝试打开excel时没有任何反应。下面是供参考的代码,任何帮助解决这个问题的人都将非常感谢。提前感谢!

代码语言:javascript
复制
function initUploader(btnId, fileType, onSuccess) {

    if (typeof fileType == "undefined") fileType = "image";

    var arrFilters = new Array();
    var url = 'user/attachmentUpload';

    switch (fileType) {
        case "image": 
            arrFilters = [{title : "Image files", extensions : "jpg,jpeg,gif,png"}]; 
            url = 'assets/imgupload';
            break;
        case "xls":
            arrFilters = [{title : "Spreadsheet files", extensions : "xls,xlsx"}]; 
            url = 'user/attachmentUpload';
            break;
        case "media":
            arrFilters = [{
                title : "Media files", 
                extensions : "mpeg4,mob,3gpp,avi,wmv,mp3,m4a,ogg,wav"
            }]; 
            break; 
        case "document":      
            arrFilters = [{
                title : "Text files", 
                extensions : "doc,docx"
            },{
                title : "PDF files", 
                extensions : "pdf"
            }]; 
            break; 
        default:      
            arrFilters = [
                {
                    title : "Image files", 
                    extensions : "jpg,jpeg,gif,png"
                },
                {
                    title : "Zip files", 
                    extensions : "zip"
                },
                {
                    title : "Media files", 
                    extensions : "mpeg4,mob,3gpp,avi,wmv,mp3,m4a,ogg,wav"
                },
                {
                    title : "Spreadsheet files", 
                    extensions : "xls,xlsx"
                },
                {
                    title : "Text files", 
                    extensions : "doc,docx"
                },
                {
                    title : "PDF files", 
                    extensions : "pdf"
                }
            ]; 
            break; 
    }

    var uploader = new plupload.Uploader({
        runtimes : 'gears,html5,html4,flash,silverlight,browserplus',
        browse_button : btnId,
        //container : 'container',
        max_file_size : '10mb',
        url : url,
        flash_swf_url : 'assets/js/vendor/plupload/plupload.flash.swf',
        silverlight_xap_url : 'assets/js/vendor/plupload/plupload.silverlight.xap',
        multiple_queues : false,
        filters : arrFilters,
        resize : {width : 320, height : 240, quality : 90}
    });

    $('#'+btnId).change(function(){
        uploader.start();
    });    
    uploader.refresh();
    uploader.init();
    uploader.bind('FilesAdded', function(up, files) {
        up.refresh(); // Reposition Flash/Silverlight
        Utility.showProcessingBar();
        uploader.start();
    });
    uploader.bind('Error', function(up, err) {
        alert("Error: " + err.code + ", Message: " + err.message + (err.file ? ", File: " + err.file.name : ""));
        up.refresh(); // Reposition Flash/Silverlight
    });

    uploader.bind('FileUploaded', function(up, file, response) {
        var obj = eval('(' + response.response + ')');
        //alert('Files uploaded');
        if (typeof onSuccess == "function")
            onSuccess(obj.fileName);   
    });

}
EN

回答 3

Stack Overflow用户

发布于 2014-06-20 21:50:56

对于每个和我有同样问题的人:

我有以下HTML代码:

代码语言:javascript
复制
<div class="container" style="display:none">
    <div>
        Logo:
    </div>
    <div style="clear"></div>

    <div id="uploader">
        <div id="runtime" class="right">
            No runtime was found !
        </div>
        <div>
            <a id="pickfiles" href="#">[Select files]</a>
            <a id="uploadfiles" href="#">[Upload files]</a>
        </div>
    </div>
</div>

container被创建为对话框:

代码语言:javascript
复制
$(function(){
    $(".container").dialog({modal:true, width:400});
});

因为我们知道div最初是因为display: none而隐藏的(当然,您可以将autoOpen:false设置为对话框对象中的一个新选项),我们可以删除该样式。

在IE8中(可能是在早期版本和更高版本中),如果div被隐藏,则无法正确实例化上载程序。(返回上述错误)

在Chrome和Firefox中(我没有在Opera中测试这个问题),它工作得很好。

所以,我的建议是避免隐藏的块(即使你想创建一个模式对话框)。

我从该div中删除了display:none样式和dialog对象,现在它在IE8中工作得非常好。

为什么?我不知道为什么在IE中,object的实例不是在页面启动时创建的,而在Firefox和Chrome中,实例是正常创建的。

票数 4
EN

Stack Overflow用户

发布于 2014-06-20 22:14:28

为了获得最大的兼容性,您应该重新排列插件优先级列表。

代码语言:javascript
复制
 var uploader = new plupload.Uploader({
        runtimes : 'gears,html5,html4,flash,silverlight,browserplus',

将其替换为

代码语言:javascript
复制
 var uploader = new plupload.Uploader({
        runtimes : 'flash,html5,silverlight,browserplus,gears,html4',

确保flash文件存在,并且路径相对于js文件的位置。

代码语言:javascript
复制
flash_swf_url : 'assets/js/vendor/plupload/plupload.flash.swf',
票数 1
EN

Stack Overflow用户

发布于 2014-06-20 20:50:28

我正在使用这个jquery。

你可以尝试一下,因为我正在ie7+和我上传文件的所有浏览器中使用它。

这是我新手在这里上传js文件的代码。

代码语言:javascript
复制
<form id="uploadForm" method="post" enctype="multipart/form-data" action="javascript:void(0);" autocomplete="off">
                            <div class="vasplusfile_adds">
                                <label>Upload More</label>
                                <input type="hidden" name="myfile"  />
                                <div class="input customfile-container">
                                    <input type="file" name="uploadfile" id="file" />
                                </div>
                                <div class="clear"></div>
                                <br>
                                <div class="input" id="status" align="left" > </div>
                            </div>
                        </form>


<script>
  $(function() {
     $('#upload_file').live('change',function() { 
    $("#status").html('<div id="upload_now" class="btn">Click to Upload</div>');});
    $('#upload_now').live('click', function() { 
       $("#uploadForm").vPB({ beforeSubmit: function() { 
           $("#status").html('<div style="" align="center">Loading</div>');
            url: '',
            success: function(response) { // my response after file uploaded 
         }}).submit(); }); }); 
</script>

示例可以在my fiddle中找到。

有一个愉快的编码:)

在ie7 http://vasplus.info/demos/upload_without_page_refresh/index.php中使用实时演示

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21014586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档