在 Chrome 中加载 iframe 时不会触发“加载"事件 [英] 'load' event not firing when iframe is loaded in Chrome

查看:69
本文介绍了在 Chrome 中加载 iframe 时不会触发“加载"事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当文件是动态生成的服务器端时,我试图在我的客户端上显示一个掩码".似乎推荐的解决方法(因为它不是 ajax)是使用 iframe 并从 onload 或 done 事件中侦听以确定文件何时实际从服务器发送到客户端.

I am trying to display a 'mask' on my client while a file is dynamically generated server side. Seems like the recommend work around for this (since its not ajax) is to use an iframe and listen from the onload or done event to determine when the file has actually shipped to the client from the server.

这是我的角度代码:

    var url = // url to my api
    var e = angular.element("<iframe style='display:none' src=" + url + "></iframe>");
    e.load(function() {
        $scope.$apply(function() {
            $scope.exporting = false;  // this will remove the mask/spinner
        });
    });
    angular.element('body').append(e);

这在 Firefox 中效果很好,但在 Chrome 中没有运气.我也试过使用 onload 函数:

This works great in Firefox but no luck in Chrome. I have also tried to use the onload function:

e.onload = function()  { //unmask here }

但我在那里也没有任何运气.

But I did not have any luck there either.

想法?

推荐答案

很遗憾,如果内容是附件,则无法在 Chrome 中使用 iframe 的 onload 事件.这个答案可能会让您了解如何解决这个问题.

Unfortunately it is not possible to use an iframe's onload event in Chrome if the content is an attachment. This answer may provide you with an idea of how you can work around it.

这篇关于在 Chrome 中加载 iframe 时不会触发“加载"事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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