I need to add a link in the admin menu to an external web that opens in a new browser tab.

So I developed a module, and this is its config.xml

        <customer translate="title" module="customer">
            <!-- action>adminhtml/customer/</action -->
                <crmlink translate="title" module="crmlink">
                    <title>CRM link</title>

And then, there is a controller:

class MySpace_Crmlink_IndexController extends Mage_Core_Controller_Front_Action
    public function indexAction()

It is working fine, the link is displayed under customer menu, and it works, I'm redirected to the external page example.com, but I need to open it in a ned browser tab, and I can't do it from the controller.

Is there a way to open the external link in a new tab as a target="_blank"? I don't see a way to do it from the xml.


It seems that there is no way to achieve it with xml.

I see two possibilities :

1) In javascript : add js file in admin (by using the layout.xml of your own module). In this js file, add on event observer on the #nav a click. When a click event is triggered, check if the url match (with some this.attr('href') = 'what-ever-you-are-expecting') and use something like window.open('the-url-you-want', '_blank');


2) In php : rewrite the block class app/code/core/Mage/Adminhtml/Block/Page/Menu.php and modify the _buildMenuArray method. Change

if ($child->action) {
       $menuArr['url'] = $this->_url->getUrl((string)$child->action, array('_cache_secret_key' => true));
} else {
       $menuArr['url'] = '#';
       $menuArr['click'] = 'return false';

with something like

if ($child->action) {
   if((string)$child->action == 'your-action'){
          $menuArr['url'] = '#';
          $menuArr['click'] = 'window.open("the-url-you-want","_blank")';
   else {
       $menuArr['url'] = $this->_url->getUrl((string)$child->action, array('_cache_secret_key' => true));
} else {
       $menuArr['url'] = '#';
       $menuArr['click'] = 'return false';

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.