6

I want to use javascript file in Magento 2.3 footer before the body and simple javascript, not jQuery.
How can I do that? I have added requirejs-config.js file in module/view/frontend code is

 var config = {
        map: {
            '*': {
                hello:'module_name/js/hello',
            }
        }
    };

and i have hello.js file in web/js folder but that javascript is not working at all . and most important is i want to add that file in the footer .

0

From backend go to content->design->configuration then edit your theme :

now in footer section you can add javascript like this :

enter image description here

or you can add too from your theme vendor/theme/Magento_Theme/layout/default.xml ; before body end not inside footer

<referenceContainer name="before.body.end">
<block class="\Magento\Framework\View\Element\Template" template="Vendor_Module::customjs.phtml" name="module_js"/></referenceContainer>

then in your template customjs.phtml you can add js like this :

 <script> 
    // you can do whatever you want here with pure javascript
 </script>
| improve this answer | |

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.