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
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