首页 > 解决方案 > 从 srcdoc 设置内容时的 iframe onload 事件

问题描述

如何为从属性加载的 iframe 指定 onloadsrcdoc属性。例如:

<iframe id="Content" runat="server" srcdoc="Large HTML contents that are set from the server"></iframe>

我正在使用 asp.net 网络表单来填充来自另一台服务器的内容。

但是,触发 iframe 的 onload 的正常方法如下,但这不起作用:


$(function () {

    var iframe = document.getElementById(DocumentViewer.GetFrameClientID());

    console.log({iframe}) // OK

    iframe.onload = function () { // Never Trigger unless i add a src attribute instead of srcdoc
        console.log('loaded')
    }
})

我发现 2018 年在 github 上报告的一个问题“加载”事件处理程序被提前为 iframe.srcdoc 调用

有什么线索吗?

标签: javascripthtmliframe

解决方案


推荐阅读