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.
button
element. btn
for the Eyedropper execution.EyeDropper
interface is supported in the browser by checking if the window.EyeDropper
property is defined.btn
.EyeDropper
object and invoke the open
method. 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.Note: The
EyeDropper
interface is available only in secure contexts (HTTPS). Because it’s still in the experimental phase, please refer to browser support here.
RELATED TAGS
CONTRIBUTOR
View all Courses