We are testing a marketing campaign that requires that their JavaScript code be added between the end body tag and the end html tag. I have seen this on several sites using their service, and this is where the code has to go. It cannot be in the body section.

For now, we just want this code on one page. Is this possible, and how can it be done?

Thanks.

Comments

nevets’s picture

You can add the javescript using drupal_add_js() something like

drupal_add_js('path to js file', 'module', 'footer');

or

$js = '... your js code here';
drupal_add_js($js, 'inline', 'footer');
roper.’s picture

That'll still be inside the body I'm afraid.

For this, you'll probably have to edit your theme's page.tpl.php file. You can just hard code your script where you want it in there. If you want it just on one page like you said, try something like:

...
</body>
<?php if ($_GET['q'] == 'the/path/you/want'): ?>
  <script type="text/javascript">
    ... custom script here ...
  </script>
<?php endif; ?>
</html>

quasi-edit: Wait a minute, can you even put <script> outside the body? Are you sure you're not supposed to put it JUST BEFORE the closing body tag? That's usually where these types of things go (google analytics, etc)... In which case use nevets' approach above.

hp9’s picture

Thanks.

That worked great, using $_GET['q'].

According to the marketing company, their code does work after the end body tag.