Skip to content

magento man

How to call javascript function from Observer file in Magento 2

I have created a custom js file in my custom module. appcodeVendorModuleviewfrontendlayoutdefault.xml <?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=”Vendor_Module::js/test.js”/> </head> appcodeVendorModuleviewfrontendwebjstest.js function Test(json){ console.log(‘Test Web’,json); } Then used add to cart event. appcodeVednorModuleetcevents.xml <?xml version=”1.0″?> <config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:Event/etc/events.xsd”> <event… Read More »How to call javascript function from Observer file in Magento 2