css - Detect support for -webkit-filter with javascript -


using javascript, how detect if browser supports webkit filters?

based on info provided @ default css filter values brightness , contrast, have tried following , few of other default values:

 if (window.matchmedia && window.matchmedia("( -webkit-filter:opacity(1) )").matches) {  alert("supported");  }else{  alert("not supported");  } 

an relatively easy way test whether css property supported following:

  1. create element
  2. apply css in question element
  3. read value - if same value set in step 2, supported, otherwise not

js:

var e = document.queryselector("img"); e.style.webkitfilter = "grayscale(1)"; if(window.getcomputedstyle(e).webkitfilter == "grayscale(1)"){    "supported!"; } 

see example


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -