javascript - How to find out if something is one of the HTML color names without having to check every single one? -


this question has answer here:

i have string texarea, want find out if string 1 of html color names here). know compare string every single one, uses quite space , isn't good. there function maybe iscolorname(color)? or won't around checking every single one?

this question offers partial anwsers : javascript function convert color names hex codes

a complete 1 : create in memory canvas , :

if (suspectedcolor.indexof('(')>=0 || suspectedcolor.indexof('#')>=0) {    // see http://www.w3.org/tr/2dcontext/#dom-context-2d-fillstyle    iscolorname = false; } else {     context.fillstyle = suspectedcolor;     iscolorname = context.fillstyle!="#000000" ; // ok, let exercice check colorname isn't black } 

it works because of :

context . fillstyle [ = value ] returns current style used filling shapes.

can set, change fill style.

the style can either string containing css color, or canvasgradient or canvaspattern object. invalid values ignored.

(from http://www.w3.org/tr/2dcontext/#dom-context-2d-fillstyle)


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -