Magento – Magento controller – Redirect to external URL in new window

controllersredirect

I have a admin controller which redirects to an external url using the following code

public function indexAction()
{
$url = 'http://www.example.com/';
    $this->getResponse()->setRedirect($url);
}

Is there anyway to change this so it opens the link into a new window as opposed to redirecting the current page?

Best Answer

This is not possible from the server side. What I would suggest is call the action via ajax and then on success write some JavaScript that opens a new tab (note that some browsers will open a new tab and some will open a new window from JavaScript).

If you want to return json from your action the following lines would help.

$this->getResponse()->setHeader('Content-type', 'application/json');
$this->getResponse()->setBody(json_encode($json));
Related Topic