To add javascript, you can use:
drupal_add_js
And similar for css:
drupal_add_css
But what if I just want to add html at the end of my page. I.e. Add a div with some text in it at the end of the page?
To add javascript, you can use:
drupal_add_js
And similar for css:
drupal_add_css
But what if I just want to add html at the end of my page. I.e. Add a div with some text in it at the end of the page?
...or, probably not as recommended as the other answers, but more direct, you can add the html straight to the page.tpl.php file.
I dont' recommend using block , as its overkill for just adding some elements on the footer. Here is the hook that you can use to add the content before
</body>
tag for Drupal 7 .A lot of suggestions here work if you want your alteration to be theme-based, but if you want this to come from a module, using a block region, page template or page prepocess won't cut it, because you're tying the alteration to the theme.
From a modular standpoint, the following options are best:
hook_footer() -- http://api.drupal.org/api/function/hook_footer/6 :: my_module_footer() should return a string of HTML, which can even be javascript. E.g.
You can use drupal $_GET['q'] to get the page URL and have that return be conditional for the page URL.
Otherwise, I sometimes use $GLOBALS["_add_my_footer"] as a boolean, and set it at various points in the module, then in hook_footer(), see if it is true.
drupal_add_js -- api.drupal.org/api/drupal/includes--common.inc/function/drupal_add_js/6 :: You can use this to add javascript to the footer by setting the $scope parameter to "footer" -- e.g.
Note that I put that drupal_add_js into hook_init() -- I did that because if you don't, the script could get lost when using Drupal's aggressive caching feature.
Unfortunately, there is no $scope parameter for drupal_add_css
As
hook_footer
did not survive Drupal 6, here's the equivalent function and how to implement it in Drupal 7:(From http://preprocess.me/drupal-hookfooter-in-drupal-7)
Drupal has a hook you can implement and add in whatever code you'd like to the footer of the page - hook_footer. See http://api.drupal.org/api/function/hook_footer/6
You can add the following to your theme's template.php file: