undefinedmodernizr

Modernizer is not defined


I have included this code in my script. Can someone tell me step by step how to install Modernizer in a page, in English layman point of view?

if(Modernizer.geolocation){
    alert("geolocation is supported");
}

Solution

  • "Modernizr is not defined" happens when you try to reference it somewhere in a code but have not included it previously.

    You may have your

    if(Modernizer.geolocation)
    

    call before Modernizr is included, or you have not included it at all. There is also a case when Modernizr is included but within asynchronous script (in that case, there might be something like <script src="modernizr.js" async></script>).

    How to include Modernizr - the easiest way?

    First choose your detects - a set of features your custom built version of Modernizr will test: https://modernizr.com/download

    Than save it as modernizer.js somewhere in your source tree, for example 'js/modernizr.rs'. Include it in a script tag before first Modernizr call. Like:

    <script src="js/modernizr.rs"></script>
    <script>
    if(Modernizer.geolocation){
        alert("geolocation is supported");
    }
    </script>