Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash runtime doesn't work in IE8 using PLupload

I have the simple javascript function inside $(function() { ... }); body

var uploader = new plupload.Uploader({
         runtimes: 'html5,flash,silverlight',
         browse_button: 'pickfiles',
         container: 'uploader',
         max_file_size: '20mb',
         unique_names: true,
         multiple_queues: false,
         //drop_element: 'dropzone',
         url: '/Home/Upload',
         flash_swf_url: '../../../Scripts/upload/plupload.flash.swf',
         silverlight_xap_url: '../../../Scripts/upload/plupload.silverlight.xap',
         filters: [
               { title: "Image files", extensions: "jpg,gif,png" },
               { title: "Zip files", extensions: "zip" }
           ],
         chunk_size: '2mb',
         resize: { width: 320, height: 240, quality: 90 }
      });

      uploader.bind("Init", function (up, params) {
         $("#runtime").html("<div>Current runtime: " + params.runtime + "</div>");
      });

      $("#uploadfiles").bind("click", function (e) {
         uploader.start();
         e.preventDefault();
      });

      uploader.init();

      uploader.bind("FilesAdded", function (up, files) {
         $.each(files, function (i, file) {
            $('#runtime').append(
                '<div id="' + file.id + '">' +
                    file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +
           '</div>');
         });
         up.refresh();
      });

      uploader.bind("UploaderProgress", function (up, file) {
         $("#" + file.id + " b").html(file.percent + "%");
      });

      uploader.bind("Error", function (up, file) {
         $('#runtime').append("<div>Error: " + err.code +
                ", Message: " + err.message +
                (err.file ? ", File: " + err.file.name : "") +
                "</div>");
         up.refresh();
      });

      uploader.bind("FileUploaded", function (up, file) {
         $("#" + file.id + " b").html("100%");
      });

and HTML code

<div class="container">
                  <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>

The error is shown in the following picture: enter image description here

http://i.imgur.com/5t0sT.jpg (to view full size)

I see there that is a problem with file filters. I run PLUpload.com examples on IE8 and it works fine with Flash runtime.

On other browsers, my uploader works perfectly. Also, I have installed the latest version of Flash for ALL browsers (IE8,FF9,Chrome 16) but the problem insists in IE8.

ISSUE FIXED: do not insert uploader object into div which has visibility:hidden or display:none property.

like image 427
Snake Eyes Avatar asked Jan 04 '12 07:01

Snake Eyes


1 Answers

For everyone who has same problem as me:

I had the following HTML code

<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>

The class container was created as dialog

$(function()
{
$(".container").dialog({modal:true, width:400});
});

As we know that DIV is initial hidden because of dispaly:none (of course, you can set up autoOpen:false as a new option in dialog object) and remove the style.

In IE8 (probably in earlier and later version) the uploader cannot be good instantiated if the div is hidden. (Returns the above error)

In Chrome and Firefox (I don't test this issue in Opera) works fine.

So, my advice is to avoid hidden block (even if you wish to create modal dialog).

I removed the display:none style and dialog object from that div and now works very good in IE8.

Why ? I don't know why in IE, the instance of object is not created at startup of page, though in Firefox and Chrome, the instance was created normally.

like image 149
Snake Eyes Avatar answered Oct 19 '22 16:10

Snake Eyes