Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6695569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:14:14+00:00 2026-05-26T06:14:14+00:00

How could I check with simple JavaScript if the browser supports the HTML5 input

  • 0

How could I check with “simple” JavaScript if the browser supports the HTML5 input type attribute color? (Note: I don’t want to use Modernizr)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:14:15+00:00Added an answer on May 26, 2026 at 6:14 am

    A good way can often be to look through the Modernizr source code. Here is the relevant chunk:

    // Run through HTML5's new input types to see if the UA understands any.
    //   This is put behind the tests runloop because it doesn't return a
    //   true/false like all the other tests; instead, it returns an object
    //   containing each input type with its corresponding true/false value
    
    // Big thanks to @miketaylr for the html5 forms expertise. http://miketaylr.com/
    Modernizr['inputtypes'] = (function(props) {
    
        for ( var i = 0, bool, inputElemType, defaultView, len = props.length; i < len; i++ ) {
    
            inputElem.setAttribute('type', inputElemType = props[i]);
            bool = inputElem.type !== 'text';
    
            // We first check to see if the type we give it sticks..
            // If the type does, we feed it a textual value, which shouldn't be valid.
            // If the value doesn't stick, we know there's input sanitization which infers a custom UI
            if ( bool ) {
    
                inputElem.value         = smile;
                inputElem.style.cssText = 'position:absolute;visibility:hidden;';
    
                if ( /^range$/.test(inputElemType) && inputElem.style.WebkitAppearance !== undefined ) {
    
                  docElement.appendChild(inputElem);
                  defaultView = document.defaultView;
    
                  // Safari 2-4 allows the smiley as a value, despite making a slider
                  bool =  defaultView.getComputedStyle &&
                          defaultView.getComputedStyle(inputElem, null).WebkitAppearance !== 'textfield' &&
                          // Mobile android web browser has false positive, so must
                          // check the height to see if the widget is actually there.
                          (inputElem.offsetHeight !== 0);
    
                  docElement.removeChild(inputElem);
    
                } else if ( /^(search|tel)$/.test(inputElemType) ){
                  // Spec doesnt define any special parsing or detectable UI
                  //   behaviors so we pass these through as true
    
                  // Interestingly, opera fails the earlier test, so it doesn't
                  //  even make it here.
    
                } else if ( /^(url|email)$/.test(inputElemType) ) {
                  // Real url and email support comes with prebaked validation.
                  bool = inputElem.checkValidity && inputElem.checkValidity() === false;
    
                } else if ( /^color$/.test(inputElemType) ) {
                    // chuck into DOM and force reflow for Opera bug in 11.00
                    // github.com/Modernizr/Modernizr/issues#issue/159
                    docElement.appendChild(inputElem);
                    docElement.offsetWidth;
                    bool = inputElem.value != smile;
                    docElement.removeChild(inputElem);
    
                } else {
                  // If the upgraded input compontent rejects the :) text, we got a winner
                  bool = inputElem.value != smile;
                }
            }
    
            inputs[ props[i] ] = !!bool;
        }
        return inputs;
    })('search tel url email datetime date month week time datetime-local number range color'.split(' '));
    

    Cut down to just detect type=”color”,

    var supportsColorInput = (function() {
        var inputElem = document.createElement('input'), bool, docElement = document.documentElement, smile = ':)';
    
        inputElem.setAttribute('type', 'color');
        bool = inputElem.type !== 'text';
    
        // We first check to see if the type we give it sticks..
        // If the type does, we feed it a textual value, which shouldn't be valid.
        // If the value doesn't stick, we know there's input sanitization which infers a custom UI
        if (bool) {
    
            inputElem.value         = smile;
            inputElem.style.cssText = 'position:absolute;visibility:hidden;';
    
            // chuck into DOM and force reflow for Opera bug in 11.00
            // github.com/Modernizr/Modernizr/issues#issue/159
            docElement.appendChild(inputElem);
            docElement.offsetWidth;
            bool = inputElem.value != smile;
            docElement.removeChild(inputElem);
        }
    
        return bool;
    })();
    

    As you can see, it’s not the most trivial thing, and can change; that’s why including something like Modernizr can be a good idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following scenaio, how could I make use of AJAX to check if
When making a simple WYSIWYG editor with JavaScript for a textarea I can check
Is there a Javascript library (preferably a jQuery plugin) or simple mechanism to check
I was wondering how I could check if a device driver is loaded using
How could I check if a number is a perfect square? Speed is of
Please could someone post an example of how to check if an element exists
If I wanted to find checked check boxes on an ASP.NET page I could
I'm writing some JavaScript that interacts with a browser plugin (add-on in Firefox, ActiveX
I'm working on a simple javascript login for a site, and have come up
I am working on making a simple Javascript game and need to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.