Posts Tagged ‘javascript’

(JQuery) Uncaught TypeError: Property ‘$’ of object [object someObject] is not a function

Friday, March 30th, 2012

This can happen for instance when JQuery has not been fully loaded before trying to execute JQuery code.
Using $(document).ready(function($) is one way to solve this, as this should wait until JQuery is fully loaded.

<script type="text/javascript">
  $(document).ready(function($) {
    //some awsome jquery code
  });
</script>

Finding the filename of a path (or any substring from a string) using javascript

Wednesday, March 28th, 2012

To find the part of a string after the last \ using javascript the following can be used.

alert( this.value.substring(this.value.lastIndexOf("\\")+1) );

Magento: Redirecting from inside a view

Thursday, September 30th, 2010

To redirect before headers are started to be sent (for instance from inside a controller) the following works:

Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('portal'));

This will redirect to the page called portal.

However if you try to do this from a view then you will get an error message about headers already having been sent.
If you need to do a redirect form inside a view then using javascript is one way to do this:

echo 'Due to SOMEREASON you are being redirected <a herf="' . Mage::getUrl('portal') . '">Please click here if nothing happens</a>';
		echo '<script type="text/javascript">
		<!--
		window.location = "' . Mage::getUrl('portal') . '"
		//-->
		</script>';

However a tip is to reconsider if you really need to do the redirect from the view, doing it from the controller is a lot easier and quicker.