Reputation: 9329
I'm currently using html5 boilerplate, which puts jQuery and your plugins into the footer. The only problem is, I use the same footer.php file in every page. How do I go about including page specific functions if the plugins aren't loaded yet? I.e.
<?php include_layout_template('header.php', '../');?>
<div id='mediaspace'>This text will be replaced</div>
<!-- Video for this page: -->
<script type='text/javascript'>
jwplayer('mediaspace').setup({
'flashplayer': '../resources/player.swf',
'file': 'http://content.longtailvideo.com/videos/flvplayer.flv',
'controlbar': 'bottom',
'width': '470',
'height': '320'
});
</script>
<?php //This file has the jwplayer function in it:
include_layout_template('footer.php', '../'); ?>
Doing this I get
Uncaught ReferenceError: jwplayer is not defined
Is it going to be easier to just put the plugin includes in the header? How do people usually tackle stuff like this in boilerplate/loading scripts at the end?
Upvotes: 1
Views: 2907
Reputation: 963
The “jwplayer is not defined” ReferenceError is exactly what it says it is. Your jwplayer reference is being called before your jwplayer.js file is loaded, which defines your jwplayer function.
If you can’t move the jwplayer.js file to the head of your document (so it’s loaded before you call jwplayer()), then you need to rethink how and when this script will be called.
I’m assuming the ‘mediaspace’ is referencing the id of an object/div? If so, leave that in the middle of the page where it belongs, and move the script below the footer.php include.
Upvotes: 0
Reputation: 536
Have you tried document.onready() function? So that the script will fire once the page is ready.
Upvotes: 1