We can use the interface to initiate the eyedropper tool to select a color code from the screen.
Creating a new object for the
EyeDropper interface will get a new
EyeDropper instance. The
EyeDropper interface contains an open method that will open the eyedropper. This method returns a promise. That occurs when the user selects a color from the screen.
We can check if our browser supports
EyeDropper by checking if the
window.EyeDropper property is defined.
The code below demonstrates how to use the
EyeDropper interface to pick a color from the screen.
btnfor the Eyedropper execution.
EyeDropperinterface is supported in the browser by checking if the
window.EyeDropperproperty is defined.
EyeDropperobject and invoke the
openmethod. This method will open the eyedropper tool. This method returns a promise which is resolved when the user selects a color. The details of the chosen color are available when we resolve the promise.
EyeDropperinterface is available only in secure contexts (HTTPS). Because it’s still in the experimental phase, please refer to browser support here.
View all Courses