首页 > 解决方案 > 我的 jQuery 函数在移动设备上的 Google Chrome 上不起作用

问题描述

我编写了一个必须在 Wordpress 内置网站上运行的功能,以显示 facebook messenger 的聊天或一个链接,如果在移动设备上,该链接将指向我的 messenger 应用程序。

我已经在桌面上的 Chrome 和 FireFox 上测试了该功能,它按预期工作。但是,在移动设备上,它仅适用于 firefox 和设备的默认浏览器,但不适用于 Chrome。

下面我输入涉及的代码部分。

<style>
.fb_reset {
    display: none;
}
.campaign-alert {
    display: none;
    position: fixed;
    bottom: 18px;
    right: 18px;
    z-index: 100000;
}

<div id="fb-root" class="fb_reset">fb-chat</div>

<div id="campaign-alert" class="campaign-alert">fb-link</div>

<script type="text/javascript">
jQuery(window).on('load',function () {
    if (jQuery(window).width() < 990) {
        let script = document.createElement('script');
        script.src = "control facebook login";
        document.head.append(script);
        script.onload = function myFunction1() {
            document.getElementById('campaign-alert').style.display = 'none';
            document.getElementById('fb-root').style.display = 'block';
        }
        script.onerror = function myFunction2() {
            document.getElementById('fb-root').style.display = 'none';
            document.getElementById('campaign-alert').style.display = 'block';
        }
    }
    else {
        let script = document.createElement('script');
        script.src = "control facebook login";
        document.head.append(script);
        script.onload = function myFunction1() {
            document.getElementById('campaign-alert').style.display = 'none';
            document.getElementById('fb-root').style.display = 'block';
        }
        script.onerror = function myFunction2() {
            document.getElementById('campaign-alert').style.display = 'none';
            document.getElementById('fb-root').style.display = 'block';
        }          
    }    
});

标签: wordpressjquery-mobile

解决方案


推荐阅读