[英]jQuery-File-Upload iframe fallback detection
Using blueimp's jQuery-File-Upload at https://github.com/blueimp/jQuery-File-Upload 在https://github.com/blueimp/jQuery-File-Upload上使用blueimp的jQuery-File-Upload
My application is running on many older browsers. 我的应用程序在许多旧版浏览器上运行。 File uploading has a long list of compatibility constraints.
文件上传有很多兼容性约束。 I'd like to simply detect when the fileuploader has gracefully fallen back to using iframe transport.
我想简单地检测文件上载器何时优雅地使用iframe传输。 I would like to detect this in the jQuery where the fileupload is being used similar to this example:
我想在使用fileupload的jQuery中检测到这个,类似于这个例子:
var using_iframe_transport = false;
this_file_input.fileupload({
dataType: 'json',
url: "http://api.cloudinary.com/v1_1/my_account/image/upload",
//as we send the file upload, record whether it is using iframe
send: function (e, data) {
if (e.iframe_fallback){ //is there a variable like this that exists in the plugin?
using_iframe_transport = true;
}
}
});//end fileupload
if (using_iframe_transport){
//do something
}
It is possible to use this code in the 'progress', 'done', or 'always' callback: 可以在'progress','done'或'always'回调中使用此代码:
...
progress: function(e){ //or 'done' or 'always'
if($('iframe').length){
using_iframe_transport = true;
}
}
...
However these callbacks are not always made as reported at https://github.com/blueimp/jQuery-File-Upload/issues/461#issuecomment-9299307 但是,这些回调并不总是按照https://github.com/blueimp/jQuery-File-Upload/issues/461#issuecomment-9299307所报告的那样进行。
My biggest concerns are supporting IE6 and Android 2.3 default browser. 我最关心的是支持IE6和Android 2.3默认浏览器。 Thanks!
谢谢!
Looks like the method that controls whether iframe is used or not is _initDataSettings which uses _isXHRUpload to determine whether to use it or not. 看起来控制是否使用iframe的方法是_initDataSettings,它使用_isXHRUpload来确定是否使用它。 Since this is a private method and cannot be called externally, you can use the following:
由于这是一个私有方法,无法在外部调用,因此可以使用以下命令:
options = this_file_input.fileupload('option');
use_xhr = !options.forceIframeTransport &&
((!options.multipart && $.support.xhrFileUpload) ||
$.support.xhrFormDataFileUpload);
If use_xhr is false iframe transport is used. 如果use_xhr为false,则使用iframe传输。
Alternatively, if you are ok with waiting until the send event, you can look at data.dataType, if it starts with "iframe", you are using the iframe fallback. 或者,如果您可以等到发送事件,则可以查看data.dataType,如果它以“iframe”开头,则表示您正在使用iframe回退。
It's possible. 这是可能的。 However, it must be done within the asynchronous context of the fileupload plugin.
但是,它必须在fileupload插件的异步上下文中完成。 If you wish to use your boolean variable
using_iframe_transport
, it must be used in the context of a callback within the plugin . 如果您希望使用布尔变量
using_iframe_transport
,则必须在插件内的回调上下文中使用它。 Use a console.log
in each block to see which executes first. 在每个块中使用
console.log
来查看首先执行的操作。
I would try using the add
callback, as it is called as soon as a file is added. 我会尝试使用
add
callback,因为只要add
了文件就会调用它。
var using_iframe_transport = false; this_file_input.fileupload({ dataType: 'json', url: "http://api.cloudinary.com/v1_1/my_account/image/upload", //as we send the file upload, record whether it is using iframe send: function (e, data) { if (e.iframe_fallback){ //is there a variable like this that exists in the plugin? /* This is being set within the asynchronous context of the plugin. */ using_iframe_transport = true; } } });//end fileupload /* This is a synchronous process and is being evaluated prior to the plugin callbacks being executed. This logic needs to be used within a callback function. */ if (using_iframe_transport){ //do something }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.