目标移动只有javascript

时间:2017-02-23 14:17:38

标签: javascript html css prestashop prestashop-1.6

所以我希望我的购物车在移动设备上的标题中点击时始终链接,我在所有平台上都可以正常使用该脚本,但我希望将其限制为仅限移动设备。该脚本位于我的blockcart.tpl文件中(prestashop 1.6.1.9)。

{literal}
 <script type="text/javascript">
     $(".shopping_cart").click(function() {
     location.href = "{/literal}
     {$link->getPageLink($order_process,true)|escape:'html':'UTF-8'}
     {literal}"; });
 </script>
{/literal}   

有关使此脚本仅限移动设备的任何帮助吗?

我试过这个(但没有用):

{literal}
 {if isset($displayMobile)}
 <script type="text/javascript">
     $(".shopping_cart").click(function() {
     location.href = "{/literal}
     {$link->getPageLink($order_process,true)|escape:'html':'UTF-8'}
     {literal}"; });
 </script>
 {/if} 
{/literal}    

1 个答案:

答案 0 :(得分:0)

PrestaShop中有一个用于检测移动设备的PHP类。您可以使用它来检测移动设备并传递一个smarty变量来检查blockcart.tpl

$mobile = new Mobile_Detect();
if ($mobile->isMobile()) {
            $this->context->smarty->assign('ismobile', 1);
        } else {
            $this->context->smarty->assign('ismobile', 0);
        }