Redirecting Joomla's View (MVC)
Last Updated on Monday, 24 May 2010 08:31
In some cases, redirecting the view of a component of module can be easily accomplished by a bit of JavaScript. For instance, the component ccNewsletter doesn't allow for an option (as of this writing) to redirect after a successful event occurs. To accomplish this task, simply add the following code at the end of a template override for the view of the component.
<script language="javascript" type="text/javascript">
<!--
window.setTimeout('window.location="http://betweenbrain.com/"; ',1000);
// -->
</script>
You can control the time and destination of the redirect. Time is 1000 milliseconds in this case, and the destination is http://betweenbrain.com/.
For example, ccNewsleter's activate view was:
<?php
defined('_JEXEC') or die('Restricted access');
?>
><div>
<?php echo $this->pageTitle; ?>
</div>
<table>
<tr>
<td>
<?php echo $this->operationStatus; ?>
</td>
</tr>
</table>
<br/>
After the redirect code addition, it is now:
<?php
defined('_JEXEC') or die('Restricted access');
?>
<div>
<?php echo $this->pageTitle; ?>
</div>
<table>
<tr>
<td>
<?php echo $this->operationStatus; ?>
</td>
</tr>
</table>
<script language="javascript" type="text/javascript">
<!--
window.setTimeout('window.location="http://betweenbrain.com/"; ',1000);
// -->
</script>
<br/>
Download the ccNewsletter Overrides v1.1. Extract the contents to the HTML folder of your template and enjoy.
Update May 18th 2010: We've improved this code to use the base URL of the website. The new code, also available in the above download, is:
<script language="javascript" type="text/javascript">
<!--
window.setTimeout('window.location="<?php echo $this->baseurl ?>"; ',1000);
// -->
</script>