Search code examples
javascriptloadfooter

JavaScript functions in footer


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?


Solution

  • Have you tried document.onready() function? So that the script will fire once the page is ready.