0

I have JS script . I need place this script after closing tag of body using php. How can i place that script.

2 Answers 2

1

Adding a <script> tag (or any tag except a comment) outside <head> or <body> is invalid HTML. Drupal doesn't want to help you to produce invalid HTML, so it contains nothing that would help you to do this.

I would examine your motivation for doing this, and reconsider whether you want to produce a valid or invalid document. If you really want to go down the invalid route, then you may as well just edit your theme's html.tpl.php file and stick the script at the bottom, as you won't find any API methods that can be used to do it for you.

FYI, IE10+ will ignore the script altogether, Chrome and FF will honour it for now, but may not in the future, other browsers/versions will probably do various other things.

0

You can use drupal_add_js which has a $scope parameter that you can set to 'footer' or other regions depending on your theme.

2
  • Can we set before closing of the body tag using drupal_add_js ? Commented Nov 16, 2015 at 13:56
  • I thought the footer would be satisfactory but if it absolutely has to go straight after the body tag, I'd probably add it in your theme's html.tpl.php
    – joekers
    Commented Nov 16, 2015 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.