Reputation: 2675
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
Upvotes: 0
Views: 117
Reputation: 2675
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
Upvotes: 0
Reputation: 207537
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();
});
Upvotes: 4