3

I need to add javascript to just before the closing body tag. Move all Javascript includes to before </body> has is a solution but it seems to me that overriding page/html/footer.phtml will cause my module to be incompatible many themes and will take away from the automation of a simple install/uninstall.

Any guidance would be greatly appreciated.

  • Are you looking to move default Magento js files or additional/custom js files to before the </body> ? – Jason Tipton Feb 11 '15 at 20:52
  • No, I am just hoping to add an additional location to insert after-content JS. – TylersSN Feb 12 '15 at 14:04
3

Try adding this to your layout XML file.

<default>
    <reference name="before_body_end">
        <block type="core/text" name="filename.js">
            <action method="setText">
                <text><![CDATA[<script type="text/javascript" src="skin/frontend/YOUR_PACKAGE/YOUR_THEME/js/filename.js"></script>]]></text>
            </action>
        </block>
    </reference>
</default>

Be sure to replace both instances of 'filename.js'. You may also need to flush Magento's caches to see the changes. If the javascript file is located in the main js folder it may be easier to load as you won't have to worry about updating 'YOUR_PACKAGE' and 'YOUR_THEME' but this is up to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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