Few android browsers including Samsung default browsers on older devices will not support
xhr.upload.onprogress
Event. So we cannot show realtime upload progress on that browsers.
How can I detect those browsers? So I can change my setup to show progress.
Few android browsers including Samsung default browsers on older devices will not support
xhr.upload.onprogress
Event. So we cannot show realtime upload progress on that browsers.
How can I detect those browsers? So I can change my setup to show progress.
Share Improve this question edited Jun 14, 2015 at 23:58 Bergi 667k161 gold badges1k silver badges1.5k bronze badges asked Jun 14, 2015 at 22:43 VishnuVishnu 7511 gold badge7 silver badges24 bronze badges 9-
1
You could read the browsers headers. Although personally I think it would be better just doing
if(typeof xhr.upload.onprogress === 'undefined')
(or similar). This way you avoid checking against every browser. – Eric Martinez Commented Jun 14, 2015 at 22:51 - @EricMartinez getting "Object" on both level1 and level2 browsers. – Vishnu Commented Jun 14, 2015 at 23:09
- sorry, getting "null" on both level1 and level2 browsers. – Vishnu Commented Jun 14, 2015 at 23:15
-
try
XMLHttpRequestEventTarget.prototype.hasOwnProperty('onprogress')
or weblogs.asp/jeffwids/… – befzz Commented Jun 14, 2015 at 23:22 - @befzz getting true on lavel 2 but not output on level 1 (try to alert) no debugging setup – Vishnu Commented Jun 14, 2015 at 23:32
3 Answers
Reset to default 3Simply :
var xhr = new XMLHttpRequest();
if ( xhr && ('upload' in xhr) && ('onprogress' in xhr.upload) ) // attach event...
So if you want a function :
function supportAjaxUploadProgressEvents() {
var xhr = new XMLHttpRequest();
return !! (xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
}
hm. tested a very old Firefox's. 3.5.2.
first version that have (new XMLHttpRequest).upload
property.
Current version Chrome:
send(1); //progress 1 of 1 send(40000000_chars); // 1,2 or more progress events.
Firefox 3.5.2:
send(1); //no progress events. send(40000000_chars); // some progress events.
So if browser sending time is not big, there is no pregress
events on old browsers.
But load
event with .loaded == .total
is fired normally.
Current conclusion: data was send too fast for old browsers.
The below was tested in FF 3.5.2 to return false
, but for latest Chrome/FF/IE11 true
The exception is thrown on trying to read the onpgress
after being set.
Hope that helps,
function isSupported() {
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
try {
xhr.upload.onprogress = isSupported;
var x = xhr.upload.onprogress;
return true;
} catch(e) {
return false;
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745626602a4636845.html
评论列表(0条)