The actual use of the front-end upload plugin plupload (personal real)

Source: Internet
Author: User

A main page, which wraps an IFRAME page, in the project, this IFRAME page is wrapped in a DIV tag on the main page and is used primarily for uploading file attachments.

With the Plupload.full plug-in, the main introduction of the following several JS:

Jquery-1.11.1.js;moxie.js;plupload.full.min.js;plupload.dev.js;

CSS section:

Jquery.plupload.queue.css;

The following is the complete front-end code implemented with the plugin:

$ (window). Load (function () {var uploader = $ ("#uploader"). Pluploadqueue ({browse_button: ' uploader_browse ',//Open File Upload Button ID runtimes: ' html5,flash,silverlight,html4 ', url: "Address for transfer data address" max_file_size: ' 10MB ',//maximum attachment size unique_names: true,//defaults to False. A value of true will generate a unique file name for each uploaded file, and post it as an additional parameter to the server side, with the parameters specified asname, the value is the generated file name. Chunk_size: ' 2MB ', Unique_names:false, Flash_swf_url: ' <%=contextpath%>/scripts/plupload/js/moxie.swf ', si Lverlight_xap_url: ' <%=contextpath%>/scripts/plupload/js/moxie.xap ', PreInit: {uploadcomplete:function ()      {window.location.reload ();  }}); Uploader.init (); $ (' form '). Submit (function (e) {var uploader = $ (' #uploader '). Pluploadqueue ();  if (Uploader.files.length > 0) {//When all files is uploaded submit form uploader.bind (' statechanged ', function ()     {if (uploader.files.length = = = (uploader.total.uploaded + uploader.total.failed)) {$ (' form ') [0].submit ();  }  });  Uploader.start ();  } else {//alert (' Please upload data file first. '); } return false;}); if (uploader = = null) {return;} Uploader.bind (' uploadcomplete ', function (uploader, files) {window.location.reload ();});    Uploader.bind (' filesadded ', function (uploader, files) {var _h = 37; if (navigator.userAgent.indexOf ("MSIE 6.0") > 0) {_h = 35; } if (Uploader.files.length > 0) {$ (". Moxie-shim"). CSS ({top: $ (". Plupload_add"). Position (). Top-_h + (_H)})    ;    } else {$ (". Moxie-shim"). CSS ({top: $ (". Plupload_add"). Position (). Top-_h});    } window.parent.SetCwinHeight2 ("Claimfilelist");    }); Uploader.bind (' filesremoved ', function (uploader, files) {var _h = 37;    if (navigator.userAgent.indexOf ("MSIE 6.0") > 0) {_h = 35;    } if (Uploader.files.length > 0) {$ (". Moxie-shim"). CSS ({top: $ (". Plupload_add"). Position (). Top-_h + (_H)});    } else {$ (". Moxie-shim"). CSS ({top: $ (". Plupload_add"). Position (). Top}); } window.parent.SetCwinHeight2 ("Claimfilelist");}); Uploader.bind (' Beforeupload ', function (uploader, files) {var DocName = $ (". Plupload_delete. Plupload_file_name"). Text  ();  var urlstr = "Upload parameter save Address" uploader.setoption ("url", urlstr);  var easfiledocname = "";  var items = $ ("#SelectorOptions a");   for (var i = 0; i < items.length; i++) {if (Items[i].innertext) { Easfiledocname + = "&eas&" + items[i].innertext;  }} if (Easfiledocname.indexof ("&eas&" + DocName) < 0) {easfiledocname + = "&eas&" + docname;    } easfiledocname = Easfiledocname.substring (5);  Setcookie ("Easfiledocname", Easfiledocname, 365);  });    var easfiledocname = GetCookie ("Easfiledocname");    if (easfiledocname) {var DNS = Easfiledocname.split ("&eas&"); for (var i = 0; i < dns.length; i++) {$ ("#SelectorOptions"). Append ("<li><a href= ' javascript:void (0) ' >"    + dns[i] + "</a></li>");    }}var items = $ ("#SelectorOptions a"); $ ("#SelectorArr"). Click (function () {$ ("#SelectorOptions") [0].style.display = $ ("#SelectorOptions") [0]. Style.display = = "Block"?    "None": "Block";    });        for (var i = 0; i < items.length; i++) {Items[i].onclick = function () {$ ("#SelectorOptions"). Hide ();        $ ("#docNameInput"). Val (This.innertext);    }; }}); function Testform () {}function DeleteFile (ID) {var onreturn = confirm ("Confirm deleting attachments?");    if (!onreturn) {return;  }document.getelementbyid (' FileId '). Value = ID;  Loadingbox_simple ();  var action = "Data sending address when deleting files";  document.getElementById (' ListFile '). Action = action; document.getElementById (' ListFile '). Submit (); }function Viewdoc_old (docfile) {xmlhttp.sendreq ("post", "url", function (http_request) {var rsptext=http_requ    Est.responsetext;    var Istrue=false;    if (rsptext!= "") {var results=http_request.responsexml;    var rsflag=results.getelementsbytagname ("Rsflag") [0].childnodes;    var flag=getnodevalue (rsflag[0]);    }else{Istrue=false; Conversion error Messagebox.alert ("\u751f\u6210\u9884\u89c8\u6587\u6863\u5931\u8d25\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5\            Uff01 ");        Return }    });}    function Viewdoc (docfile) {var path = ' url ';    var params = ' claimno= ' +claimno;    var params = ';    Xmlhttp.sendreq ("Post", Path,params, Showresultinfo); Messagebox.alert ("Generating document previewView, please wait ... ");        function Showresultinfo (http_request) {var rsptext=http_request.responsetext;        alert (Rsptext);            if (rsptext!= "") {Canceldivbox ("screen_div_p", "screen_box_p", "screen_iframe_p");    Messagebox.alert (Rsptext);                                           }}

These are the code that uploads the attachment to the front end using the plugin, which is valid in the project I am currently participating in.

You need to use the Guide to refer to this address: http://www.cnblogs.com/2050/p/3913184.html

(The plugin in the Google mainstream building browser is not a problem, but there are bugs in IE and Firefox, in my project, no matter which version of the plug-in, the bug is always there (ie and Firefox in the first click Invalid), so can only think of other ways, and my approach is that after the page loaded, Make an initial refresh of the IFrame page, as shown on the next page)

The actual use of the front-end upload plugin plupload (personal real)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.