2

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

<frontend>
    <routers>
      <crmlink>
        <use>standard</use>
        <args>
          <module>MySpace_Crmlink</module>
          <frontName>crmlink</frontName>
        </args>
      </crmlink>
    </routers>
</frontend>
<adminhtml>
    <menu>
        <customer translate="title" module="customer">
            <title>Customers</title>
            <sort_order>40</sort_order>
            <!-- action>adminhtml/customer/</action -->
            <children>
                <crmlink translate="title" module="crmlink">
                    <title>CRM link</title>
                    <action>crmlink</action>
                    <sort_order>1010</sort_order>
                </crmlink>
            </children>
         </customer>
    </menu>
</adminhtml>

And then, there is a controller:

<?php
class MySpace_Crmlink_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->_redirectUrl('www.example.com');
    }
}

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.

1 Answer 1

1

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');

or

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 and acknowledge you have read our privacy policy.

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