javascript - How to detect a browser that will not support XHR2 Upload progress - Stack Overflow

Few android browsers including Samsung default browsers on older devices will not support xhr.upload.on

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
 |  Show 4 more ments

3 Answers 3

Reset to default 3

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));
}

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信