worked
worked

Reputation: 5880

HTML 5 + Progress element check?

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

Upvotes: 8

Views: 846

Answers (3)

Sleavely
Sleavely

Reputation: 1683

Another oneliner, taken from Modernizr:

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

Upvotes: 6

dtbarne
dtbarne

Reputation: 8200

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

Upvotes: 1

user1091949
user1091949

Reputation: 1933

Create a progress element and check for the max attribute:

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

Upvotes: 3

Related Questions