3

I tried adding the code to template/page/html/head.phtml

if (Mage::helper('mobiledetect')->isMobile()){
  $this->addItem('js', 'js/mobile_jsscript.js');
  $this->getLayout()->getBlock('head')->removeItem('js', 'js/normal_js_script.js');
}

Is this the correct way to add and remove js based on criteria?

Marius
  • 197,939
  • 53
  • 422
  • 830
tread
  • 1,083
  • 2
  • 13
  • 36

2 Answers2

2

removeItem() function,is working when we have add js file using addItem()

through xml code :

<action method="addItem"><type>skin_js</type><name>js/normal_js_script.js</name></action>

or php code:

$this->getLayout()->getBlock('head')->addItem('skin_js', 'js/normal_js_script.js');

Or,it may be issue with params issue in function removeItem($type,$filepath)

skin_js instead of js

$this->getLayout()->getBlock('head')->removeItem('skin_js', 'js/normal_js_script.js');

Remove Item from HEAD entity

Just like:

<action method="removeItem"><type>skin_js</type><name>js/ie6.js</name></action>
Amit Bera
  • 77,456
  • 20
  • 123
  • 237
0

Not sure whether above function returns correct results..but you can do using jquery also....refer to below link and download required script like jquery or php and replace your if condition correspoding to your downloaded script.

http://detectmobilebrowsers.com/