Is it possible to call a frontend javascript function from a plugin php file? The js function should be executed in the browser.
view/frontend/web/js/send.js
function send() {
console.log("Sending here...")
}
Plugin/plg.php
public function afterAddProduct(Cart $subject, $result, $productInfo, $requestInfo = null)
{
echo '<script>console.log("in plugin");send();</script>';
}
This is what I'm trying to do. The send function is available in the browser and I'm able to manually trigger it from browser console.
But I'm unable to get the javascript in the .php plugin file working in the browser. Even console.log("in plugin")
is not working.
Is there a way to execute clientside javascript from .php plugin file?