最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HTML 5 + Progress element check? - Stack Overflow

programmeradmin2浏览0评论

This might be very basic, or not possible, but it's alluding me and worth asking. Is there a way to check if the html 5 progress element is supported in a browser?

var progress = document.createElement('progress');

This might be very basic, or not possible, but it's alluding me and worth asking. Is there a way to check if the html 5 progress element is supported in a browser?

var progress = document.createElement('progress');
Share Improve this question asked Apr 14, 2013 at 0:35 workedworked 5,8805 gold badges56 silver badges79 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

Another oneliner, taken from Modernizr:

//returns true if progress is enabled
var supportsProgress = (document.createElement('progress').max !== undefined);

Create a progress element and check for the max attribute:

function progressIsSupported() {
  var test = document.createElement('progress');
  return (
      typeof test === 'object' &&
      'max' in test
    );
}

Nice one liner:

function supportsProgress() {
    return (t = document.createElement("progress")) && t.hasOwnProperty("max");
}

Or if you really don't want to use a global:

function supportsProgress() {
    var t = document.createElement("progress");
    return t && t.hasOwnProperty("max");
}
发布评论

评论列表(0)

  1. 暂无评论