【问题标题】:Javascript mobile redirect in Joomla 2.5Joomla 2.5 中的 Javascript 移动重定向
【发布时间】:2013-12-12 03:52:01
【问题描述】:

我有 joomla 2.5,但我们的第三方移动应用程序大师要求我们在我们的主索引页面中放置一些 javascript。为使用手机的用户将网站重定向到移动应用浏览器。

这里是代码:

<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> 

问题是:

我需要在哪里粘贴代码?

我已经将它粘贴到:标签之前的主索引模板中,并且还尝试放入 index.php 的第一行。但它不起作用。当我尝试通过我的手机打开时,它没有重定向。

有人可以帮忙吗?

【问题讨论】:

    标签: javascript redirect mobile joomla


    【解决方案1】:

    把它放在头标签之间。

    &lt;head&gt; Put in here &lt;/head&gt;

    【讨论】:

    • 当然,我已将其粘贴在 标记之前。仍然......当我尝试从我的手机打开时,没有任何反应......任何线索?
    【解决方案2】:

    您可以创建一个插件并执行代码,或者更简单的方法是将以下内容放在您的模板文件夹中的 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"; } 
         } 
      } 
    ');
    

    这会自动将代码附加到模板中的&lt;head&gt; 标记中。

    【讨论】:

      猜你喜欢
      • 2014-12-28
      • 1970-01-01
      • 2013-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-20
      • 2013-12-07
      相关资源
      最近更新 更多