Manually trigger 'open file dialog' using plupload

前端 未结 6 1808
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 08:51

I\'m using plupload to client scaling of pictures before they are uploaded. I like the feature that it gracefully falls back to html4 if the user doesn\'t have flash, silver

相关标签:
6条回答
  • 2020-12-15 09:17

    I read your problem.

    I found some articles that may help to figure this out. check them. It may help...!

    01. https://stackoverflow.com/questions/210643/in-javascript-can-i-make-a-click-event-fire-programmatically-for-a-file-input-e

    02. https://stackoverflow.com/questions/2048026/open-file-dialog-box-in-javascript

    0 讨论(0)
  • 2020-12-15 09:24

    @Per Hornshøj-Schierbeck After uploader has been init. It take few time to render input file to select. So you need to wait like below:

    this.uploader.init();
    var task = new Ext.util.DelayedTask(function () {
        var inputArray = $('div.moxie-shim input[type=file]');
        var input = inputArray.length > 1 ? inputArray[inputArray.length - 1] : 
                    inputArray[0];
        $(input).trigger('click');
     });
    
    task.delay(100);
    

    The code in javascript is similar. Worked for me with plupload 2.3.6

    Hop this help!

    0 讨论(0)
  • 2020-12-15 09:27

    If someone is searching for the HTML5 solution, here it is:

    var up= $('#uploader').pluploadQueue();
    if (up.features.triggerDialog) {
        plupload.addEvent(document.getElementById('idOtherButton'), 'click', function(e) {
            var input = document.getElementById(up.id + '_html5');
            if (input && !input.disabled) { // for some reason FF (up to 8.0.1 so far) lets to click disabled input[type=file]
                input.click();
            }
            e.preventDefault();
        }); 
    }
    
    0 讨论(0)
  • 2020-12-15 09:28

    Fallback runtimes will become irrelevant as times goes by. This means that sooner or later, we'll be all using HTML5 runtime. In case that you are using HTML5 runtime, but don't use pluploadQueue(), this will work as well:

    // Set up and initialise uploader
    var uploader = new plupload.Uploader({
      'runtimes' : 'html5',
      'browse_button' : 'id_of_the_first_button'
    
      // Other options
    });
    
    uploader.init();
    
    // Hook in the second button
    plupload.addEvent(document.getElementById('id_of_the_second_button'), 'click', function(e) {
      var input = document.getElementById(uploader.id + '_html5');
      if (input && !input.disabled) {
        input.click();
      } // if
      e.preventDefault();
    });
    
    0 讨论(0)
  • 2020-12-15 09:30

    The former solutions not worked on iPhones with plupload 2.1.2.

    The following code did the trick (jquery needed):

    $("#id_of_the_second_button").click(function() { 
        $('div.moxie-shim input[type=file]').trigger('click');
    });
    
    0 讨论(0)
  • 2020-12-15 09:38

    Ok. It doesn't seem possible to do this, so unless someone implements event handles for the silverlight and flash components i'm out of luck

    0 讨论(0)
提交回复
热议问题