So i created a custom button in the toolbar of my joomla-administration component. I want it to do something in the background but NOT to redirect to another page. Unfortunately, it always redirects to another page when i press it, no matter if i declare a $this->setRedirect-statement or if i dont.

My custom toolbar-button:

JToolBarHelper::custom('mymail.send', 'mymail_send.png', 'mymail_send.png', 'Send', false);

which calls the function

public function send()
    // does something, but is not supposed to redirect

if i call $this->setRedirect($myurl) within the function it will follow the $myurl correctly. If i dont call it, it redirects to an empty page.

What can I do to prevent the page from redirecting (or reloading) at all?


2 Answers 2


To prevent the redirect overwrite the submitbutton function in JavaScript, because usually each button calls the submitbutton function, which will submit the form. You can overwrite the function in your template file, for example.

    Joomla.submitbutton = function(task)
        if (task == "mymail.send")
          // Do something in the background with AJAX
          // See Rene Korss comment under your question for more information

This is done in the core components too. Examples:

Article: https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_content/views/article/tmpl/edit.php#L63

Banner client: https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_banners/views/client/tmpl/edit.php#L16


Yes,You can write the $this->setRedirect($myurl) with in function when you call this function that time only it will execute otherwise it can't.
You can check the condition if it's true means execute this statement $this->setRedirect($myurl) otherwise redirect to same page.

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.