I try to use this function in a plugin, but is not working, maybe because javascript doesn't have time to execute after login an I end up redirected to homepage
public function onUserAfterLogin($text) {
$app = JFactory::getApplication();
$document = JFactory::getDocument();
$document->addScriptDeclaration('document.addEventListener("message", function(event) {
alert("test");
});
');
}
I have tried with even with echo
echo '<script type="text/javascript">
alert("test");
</script>';