简体   繁体   English

Joomla 2.5中的Javascript移动重定向

[英]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. 我有joomla 2.5,但我们的第三方移动应用程序大师要求我们在主索引页面中添加一些javascript。 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. 我已经完成了将它粘贴到:标记之前的主索引模板,并且还尝试放入index.php的第一行。 But it doesnt work. 但它不起作用。 when I try to open via my mobile phone, it doesnt redirect. 当我尝试通过手机打开时,它不会重定向。

anyone can help? 谁有人可以帮忙?

把它放在头部标签之间。

<head> Put in here </head>

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: 您可以创建插件并执行代码,或者更简单的方法是将以下内容放在yout模板文件夹中的index.php文件中:

$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. 这会自动将代码附加到模板中的<head>标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM