0

i need to add a JS script in the admin HEADER tag in the admin section for all pages. how to do that?

1 Answer 1

2

Create default.xml in your own module.

Path:

app/code/Name_Space/Module_Name/view/adminhtml/layout/default.xml

And put below code:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <head>
     <script src="module_name::js/customjsfile.js"/>
   </head>
</page>
5
  • thanks, and where to save "customjsfile.js"?
    – Zorox
    Commented May 14, 2018 at 13:08
  • It should under app/code/Name_Space/Module_Name/view/adminhtml/web/js folder.
    – kunj
    Commented May 14, 2018 at 13:11
  • ONE PROBLEM, how to add a remote script? LOOKS like magetno alwasy try to use local scripts and add the website root URL before the src
    – Zorox
    Commented May 14, 2018 at 13:16
  • <script src="google.com/yourscript.js" src_type="url" /> Commented May 14, 2018 at 13:24
  • perfect. worked well
    – Zorox
    Commented May 14, 2018 at 13:55

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.