user3093782
user3093782

Reputation: 1

Javascript mobile redirect in Joomla 2.5

I have joomla 2.5, but our third party mobile app master asked us to put some javascript in our main index page. to redirect website into mobile app browser for user that using mobile phone.

here is the code :

<script language="javascript"> <!-- 
var mobile = (/iphone|ipod|android|blackberry|bb10|windows 
phone/i.test(navigator.userAgent.toLowerCase())); 
if (mobile) { 
var userAgent = navigator.userAgent.toLowerCase(); 
if ((userAgent.search("android") > -1) && !(userAgent.search("mobile") > -1)) { 
} else { 
// document.location = "http://webapp.to/test" 
var r=confirm("Open our Mobile WebApp?"); if (r==true) { 
document.location = "http://#"; } 
} 
} 
</script> 

Question is :

where do I need to paste the code?

I have done paste it into : main index template right before tag, and also trying to put in the first line of index.php. But it doesnt work. when I try to open via my mobile phone, it doesnt redirect.

anyone can help?

Upvotes: 0

Views: 253

Answers (2)

Lodder
Lodder

Reputation: 19733

You can either create a plugin and execute the code or a more simple method would be to place the following in your index.php file in yout template folder:

$doc = JFactory::getDocument();
$doc->addScriptDeclaration('
  var mobile = (/iphone|ipod|android|blackberry|bb10|windows 
  phone/i.test(navigator.userAgent.toLowerCase())); 
  if (mobile) { 
     var userAgent = navigator.userAgent.toLowerCase(); 
     if ((userAgent.search("android") > -1) && !(userAgent.search("mobile") > -1)) { 
     } 
     else { 
       // document.location = "http://webapp.to/test" 
       var r=confirm("Open our Mobile WebApp?"); if (r==true) { 
       document.location = "http://webappasia.com/artisan"; } 
     } 
  } 
');

This will automatically append the code to the <head> tags in your template.

Upvotes: 1

CRABOLO
CRABOLO

Reputation: 8793

Put it between the head tags.

<head> Put in here </head>

Upvotes: 1

Related Questions