【问题标题】:Ajax breaks when you "add website to homescreen" on iPhone当您在 iPhone 上“将网站添加到主屏幕”时,Ajax 中断
【发布时间】:2013-08-21 23:14:45
【问题描述】:

我有一个网站,它使用 ajax 在用户单击按钮时引入内容。除非有人使用移动版 Safari 的“添加到主屏幕”功能,然后使用主屏幕上的图标打开网站,否则此方法可以正常工作。

当有人从主屏幕图标打开网站时,一切正常,直到 ajax 加载部分。当有人单击该链接时,屏幕会闪烁白色,然后加载内容,但是应该在加载函数中运行的所有函数都没有实际运行。就像内容被加载了,但应该发生的动画没有发生,页面看起来很糟糕。

这是一个奇怪的问题,我无法检查问题,因为我无法访问我的控制台。

这是我的网络应用程序的链接(尚未完成)-http://chrisgjones.com/aut/1.3/

我的 ajax 负载看起来像这样

<div class="inner">
     <a href="farm.html">Link</a>
</div>

function loadProject(){

        var $load = $('#level');

        $(document).on('click','.inner a',function(e){          

            e.preventDefault();
            $this = $(this);

            var _sourceTarget = '#puzzle',
                _url= $this.attr('href');

                $load.load(_url+" "+_sourceTarget, function(){

                    animalSlider();

                    setTimeout(function(){ 
                        $('.animal-content').centerRelative();
                    }, 2000);

                    $('#level-selection').animate({'left':'-200%'}, _speed, _ease, function(){

                        $logo.animate({'top':'10%'}, _speed, _ease);
                        $loader.animate({'margin-bottom':'10px'}, _speed, _ease, function(){

                            setTimeout(function(){ 

                                $logo.animate({'top':-_logoHeight}, _speed, _ease);
                                $loader.animate({'margin-bottom':-_loaderHeight}, _speed, _ease, function(){
                                    $splash.delay(_speed).fadeOut(_speed*2);
                                });

                            }, 3000);                       

                        });

                    });

                }); // end load

        }); // end click

}   // end function

【问题讨论】:

    标签: javascript jquery iphone web-applications mobile-safari


    【解决方案1】:

    好的,所以我从脑海中删除了这个脚本,它与 HMLT5 Mobile Boilerplate 一起提供...现在可以正常工作了

    <!-- This script prevents links from opening in Mobile Safari. https://gist.github.com/1042026 -->
    
    <script>(function(a,b,c){if(c in b&&b[c]){var d,e=a.location,f=/^(a|html)$/i;a.addEventListener("click",function(a){d=a.target;while(!f.test(d.nodeName))d=d.parentNode;"href"in d&&(d.href.indexOf("http")||~d.href.indexOf(e.host))&&(a.preventDefault(),e.href=d.href)},!1)}})(document,window.navigator,"standalone")</script>
    

    【讨论】:

    • 为了看起来像原生应用,“添加到主屏幕”会隐藏地址栏。您的 JS 代码是否有可能引用 window.location 并且当您将其作为本机应用程序执行时不起作用
    【解决方案2】:

    回答第一个问题后,我无法加载图像。 (安卓)。我与其他一切的联系似乎没有,所以我怀疑这是一个连接问题。希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      • 1970-01-01
      相关资源
      最近更新 更多