OSX Safari帧加载中断 [英] OSX Safari Frame Load Interrupted

查看:401
本文介绍了OSX Safari帧加载中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的HTML网站(带有一些javascript),使用简单的锚标签来下载这样的文件:

I have a basic HTML website (with some javascript) using a simple anchor tag to download a file like so:

<a href="../resources/mexml/MexmlSamples-1.0.zip">Mexml Samples 1.0</a>

为了跟踪下载次数,我有 onclick 将事件传递给Google Analytics的处理程序,如下所示:

In order to track the number of downloads, I have an onclick handler that passes an event to Google Analytics like so:

$('#mybutton').click(function(e){ga('send','event','Download','MexmlSample','MexmlSample-1.0');});

在OS X上使用Chrome和Windows 7上的IE下载文件时,这可以正常工作。文件下载,我在GA帐户中看到了该事件。

This works as expected when downloading the file using Chrome on OS X, and IE on Windows 7. The file downloads and I see the event in my GA account.

当我在Yosemite上的Safari 8中测试时,文件 下载,但是GA很少看到这个事件。当然,我在Safari错误控制台中得到了可怕的无法加载资源:帧加载中断

When I test it in Safari 8 on Yosemite, the file does download, but GA only rarely sees the event. And of course I get the dreaded Failed to load resource: Frame load interrupted in the Safari error console.

I假设我有时因为Safari中断动作和GA代码触发之间的竞争条件而得到GA事件。

I assume that I get the GA event sometimes because of a race condition between when Safari interrupts the action and when the GA code fires.

所以可以采取任何措施来解决这个问题。 Safari以便我总是得到GA事件?

So can anything be done to fix this in Safari so that I always get the GA events?

请注意,我的问题可能与此未答复问题具有相同的根本原因:下载Excel文件时帧加载中断

Note that my question probably has the same root cause as this unanswered question: Frame load interrupted when downloading excel files

6月6日更新

我现在很困惑。我刚刚注意到,如果我打开一个新的浏览器页面到我的网站(在Safari中),然后点击下载,那么它会被GA记录下来。然而,随后的点击下载仍然是文件,但不会被GA记录。

I am now thoroughly confused. I just noticed that if I open up a new browser page to my site (in Safari), and click on the download, then it gets logged by GA. However subsequent clicks download still the file, but don't get logged by GA.

如果我关闭该窗口,并打开一个新窗口,那么第一次下载得到由GA记录。

If I close that window, and open a new one, then again the first download gets logged by GA.

相比之下,使用Chrome时,每次下载都会被GA记录下来。

In contrast, when using Chrome every download gets logged by GA.

我现在以为我可能在看错了问题。我看到的行为告诉我Safari正在使用JavaScript保持一个状态,允许第一个GA调用通过,但阻止所有后续调用。

I am now thinking that I may be looking at the wrong problem. The behavior I am seeing is telling me that Safari is maintaining a state in JavaScript that allows the first GA call to go through, but blocks all subsequent calls.

但这与Chrome运行的代码相同,所以我不知道如何开始调试问题。

But this is the same code being run by Chrome, so I don't know where to how to even start debugging the problem.

推荐答案

如果你总是想要获得ga事件,那么hitCallback可能是唯一的方法,直到修复了Safari的任何错误。我使用类似的模式从应用程序中的页面发送GA事件,这只是在rails中执行了大量数据库内容之后的重定向。将javascript重定向添加到回调中没有明显的延迟。但是我不知道如何从javascript开始下载。

If you always want to get the ga event then the hitCallback is likely the only way to go until whatever is wrong with Safari is fixed. I use a similar pattern to send a GA event from a page in an app which is just a redirect after a whole load of database stuff has been executed in rails. There is no noticeable lag from adding the javascript redirect into the callback. However I am not sure how to initiate the download from javascript off the top of my head.

ga('send','event','Download','MexmlSample','MexmlSample-1.0', {
   hitCallback: function(){
   initiateDownload();
   })

我不知道在这个例子中是否需要使用setTimeout()作为模式。

I am not aware of any need to use the setTimeout() for pattern in this instance.

这篇关于OSX Safari帧加载中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆