0

I am working with foundation 5 but I don't think this is specific to just foundation as it's more of a javascript question.

In the head of my document I load a .js file modernizr.js

then at the bottom of the body of my file I am trying to use the javascript .load() function like this

<script type="text/javascript">
    Modernizr.load(function(){
        console.log('hello world');
    });
</script>

this is causing an 'Uncaught TypeError: undefined is not a function'

I am not really sure what's going on. The page still loads and the log message comes up as expected but I don't want to just move on with uncaught exceptions in my code.

What's the issue with this function and how can I overcome this obstacle?

5
  • Is Modernizr loaded before this code? It needs to be. Modernizr.load() is for loading OTHER resources AFTER Modernizr itself is already loaded. Doc here: modernizr.com/docs/#load Commented Nov 2, 2014 at 3:19
  • hi jfriend00 yes, modernizr was already loaded in the head of the document. This script is at the bottom of the body tag below the footer. Commented Nov 2, 2014 at 3:22
  • Please reproduce this in a simple jsFiddle then because what you are reporting doesn't make sense so apparently we don't understand what is really happening and thus need to see it reproduced. Also, what are you trying to acccomplish with that .load() line? Usually, you specify some resource to load. Commented Nov 2, 2014 at 3:38
  • Here's a mock up fiddle Commented Nov 2, 2014 at 3:57
  • In the jsFiddle, it's misspelled. Should be Modernizr, not Modernizer. When that is corrected, it looks like you don't have the .load() method in your build. Commented Nov 2, 2014 at 4:01

1 Answer 1

3

Modernizr Download

Make sure you ticked the Modernizr.load while downloading the modernizr js file.

EDIT: Modernizr.load which comes from yepnope.js is deprecated which is the reason why it is not included as a part of build by default. https://github.com/SlexAxton/yepnope.js#deprecation-notice

Quoted from the page : For these reasons, we're also not going to include yepnope in the next version of Modernizr as Modernizr.load.

Please try other alternatives for a better future of your app ;)

Sign up to request clarification or add additional context in comments.

1 Comment

tejas_spy007, i've been using the cdn version, based on your message and then actually looking at the cdn version the .load() function is not included in the that file :\ it seems that I actually have to use the one downloaded from the site.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.