0

I'm trying to load an external Javascript file from a website to a local js file.. i've tried this

(function($) {  

  $("head").append('<script type="text/javascript" src="http://URL_TO_SITE/jquery.acornmediaplayer.js"></script>');

  setTimeout(function() {
    $('.jvideo').acornMediaPlayer();     

  }, 2000);

})(jQuery);

but it gives me

[object Object] has no method acornMediaPlayer

i've also tried $.getScript but it gives me the same result

1
  • Do you get the same error, after removing settimeout Commented Jan 15, 2014 at 14:19

2 Answers 2

4

My guess is you did not use getScript correctly.

jQuery.getScript( url, success);

There is a success callback when it is done. Add the function call in there and do not use the timeout.

$.getScript("http://URL_TO_SITE/jquery.acornmediaplayer.js", function(){
    $('.jvideo').acornMediaPlayer();
});
Sign up to request clarification or add additional context in comments.

4 Comments

actually i used it that way exactly and the funny thing is.. it's working when i put the script locally and use append to the head
So you get the same error that acornMediaPlayer is not defined? Or is it the items do not load?
acornMediaPlayer is not defined?
Not sure what your problem is since this loads with no error: jsfiddle.net/FQX2w
0

ok i got the problem.. it suppose to be putted inside $(window).load like this

$(window).load(function(){
    (function($) {  

  $("head").append('<script type="text/javascript" src="http://URL_TO_SITE/jquery.acornmediaplayer.js"></script>');

  setTimeout(function() {
    $('.jvideo').acornMediaPlayer();     

  }, 2000);

})(jQuery);
});

voila

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.