1. /projectname/skin/frontend/base/default/js/myproduct.js

<?xml version=”1.0″ encoding=”UTF-8″?>
<layout version=”0.1.0″>
<catalog_product_view>
<reference name=”head”>
<action method=”addItem”>
<type>skin_js</type><name>js/myproduct.js</name>
</action>
</reference>
</catalog_product_view>
</layout>

2. /projectname/js/myproduct.js

<layout version=”0.1.0″>
<catalog_product_view translate=”label”>
<reference name=”head”>
<action method=”addJs”>myproduct.js</action>
</reference>
</catalog_product_view>
</layout>

 

Another way to add js. It will use when you want to add js before your custom js.

f.e – bundle.js is load after your custom js file and instead of  after we need that file before my custom js.

How to add js in magento

There is a two way to add js

<?xml version=”1.0″ encoding=”UTF-8″?>
<layout version=”0.1.0″>
<catalog_product_view>
<reference name=”head”>
<action method=”removeItem”>
<type>skin_js</type><name>js/bundle.js</name>
</action>
<action method=”addItem”>
<type>skin_js</type><name>js/bundle.js</name>
</action>
<action method=”addItem”>
<type>skin_js</type><name>js/customJs/myproduct.js</name>
</action>
</reference>
<reference name=”content”>
<block name=”product.info.addtocart”>
<block type=”core/template” name=”woffice_ajaxcall” template=”Ajaxcall/ajaxcall.phtml”></block>
<!– <action method=”append”><block>woffice_ajaxcall</block></action> –>
</block>
</reference>
</catalog_product_view>
</layout>

Advertisements