2

I have a custom extension that has a javascript file which need to run on every page in magento 2 backend to use jquery and ajax function, is there a way to do this action with custom extension?

1 Answer 1

0

You wiil have to make YourVendor/YourModule/view/adminhtml/default.xml for this and paste following code.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <script src="YourVendor_YourModule::js/yourcustomjs.js"></script>
    </head>
</page>

and paste your js code in YourVendor/YourModule/view/adminhtml/web/js/yourcustomjs.js

Do remember to deploy static content and flushing and cleaning cache

php bin/magento setup:static-content:deploy

php bin/magento cache:flush

php bin/magento cache:clean

and give required permissions

chmod 777 -R var pub

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.