Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect a browser that will not support XHR2 Upload 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.

like image 955
Vishnu Avatar asked Jun 14 '15 22:06

Vishnu


2 Answers

Simply :

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));
}
like image 172
fred727 Avatar answered Oct 22 '22 20:10

fred727


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.
like image 40
befzz Avatar answered Oct 22 '22 22:10

befzz