转储文件时的Iframe的onLoad不会火? [英] Iframe onLoad won't fire when dumping a file?
问题描述
我有一个简单的 IFRAME
< IFRAME类=IFRSRC =有关:空白>< / IFRAME>
其中有的onload
处理程序连接到它。
$(IFR)。在('负荷',函数(){
警报(iframe中加载)
});
还有2个按钮:
当我preSS的第一个按钮(它设置一个站点(其中没关系) - 它的确实警告:
然而,当我将它设置为的我的页面 (其中转储图片) - 图片的是下载但它能源部不火的的onload
当我美元的的第二的按钮,它重定向到一个网页,其中的code为p $ PSS:
Response.Clear();
Response.AddHeader(内容处置,附件;文件名= /图像/ about_us_bkg.jpg);
Response.AddHeader(内容长度,File.ReadAllBytes(使用Server.Mappath(〜/图片/ about_us_bkg.jpg))Length.ToString());
Response.TransmitFile(使用Server.Mappath(〜/图片/ about_us_bkg.jpg));
到Response.End();
我相信这是关系到到Response.End();
问:
-
为什么?(如果有的话),它是由
到Response.End
影响?我指的是浏览器的并发送响应(作为图片)....所以? -
我怎样才能解决这个,这样当图片加载(或iframe完成),这将触发onload事件?
P.S。我为什么需要它?
当用户preSS下载文件,在客户端显示-I加载动画和的的onload想删除加载动画。
为什么?(如果有的话),它是由到Response.End影响?我的意思是浏览器
并发送(如图片)的响应,因此请求完成....没有?
块引用>我不认为这是关系到到Response.End(除非当你删除到Response.End作品)
您可以使用Context.ApplicationInstance.CompleteRequest()
而不是到Response.End
(见的)的//stackoverflow.com/q/14566781/1236044\">Correct使用
我怎样才能解决这个问题,使画面加载(或iframe完成)时,
这将触发onload事件?
块引用>我认为问题来自于一个事实,你的iframe中的内容不是HTML文档或img元素。所以它不会触发任何负载的事件。
您可以有你的aspx页面有两种不同的行为上查询字符串参数变化(或者只是有两页):
- 一个服务于图像(比如 img.aspx 的,你已经有了一个)
- 之一,说的 document.aspx 的,该URL将被用作
的src
你的IFRAME $属性C $ C>。的 document.aspx 的构建含有
的src
将是一个img元素整个HTML文档的 img.aspx 的希望这将有助于
I have a simple
iframe
<iframe class="ifr" src="about:blank"></iframe>
Which has
onload
handler attached to it.$(".ifr").on('load',function (){ alert("iframe loaded") });
There is also 2 buttons :
When I press the first button ( which sets to a site ( nevermind which) - it does alert :
However when I set it to mypage (which dumps a picture) - the picture is downloaded but it doe not fire the
onload
.When I press on the second buttons it redirects to a page which its code is:
Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=/images/about_us_bkg.jpg"); Response.AddHeader("content-length", File.ReadAllBytes(Server.MapPath("~/images/about_us_bkg.jpg")).Length.ToString()); Response.TransmitFile(Server.MapPath("~/images/about_us_bkg.jpg")); Response.End();
I believe it is related to
Response.End();
.Question :
Why (if ever) it is affected by
Response.End
? I mean the browser did send a response ( as a picture) ....so?How can I solve this so that when the picture loads( or iframe completes) , it will fire the onload event ?
p.s. why do I need it ?
When a user press "download file" , in client side -I show loading animation and the
onload
suppose to remove the "loading" animation.解决方案Why (if ever) it is affected by Response.End ? I mean the browser did send a response ( as a picture) , so the request is completed ....no?
I don't think it is related to Response.End (unless it works when you remove the Response.End) You may use
Context.ApplicationInstance.CompleteRequest()
instead ofResponse.End
( see Correct usage of Asp.Net Response.TransmitFile and Response.End() )How can I solve this so that when the picture loads( or iframe completes) , it will fire the onload event ?
I think the problem comes from the fact that your iframe content is not an html document or an img element. So it does not trigger any load event.
You may have your aspx page have two different behaviours varying on a query string parameter (or just have two pages) :
- one that serves the image (say img.aspx, the one you already have)
- one, say document.aspx, which url will be used as
src
attribute of youriframe
. document.aspx builds a whole html document containing an img element whichsrc
will be img.aspxHope this will help
这篇关于转储文件时的Iframe的onLoad不会火?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!