【问题标题】:MS CRM 2011 IFRAME "load" event not firedMS CRM 2011 IFRAME“加载”事件未触发
【发布时间】:2015-02-05 10:42:52
【问题描述】:

我有 MS CRM 2011(5.0.9690.2243,按需)HTML Web 资源,可在 IFRAME 中加载实体:

<HTML>
    <HEAD>
        <SCRIPT type=text/javascript src="http://code.jquery.com/jquery-latest.min.js"></SCRIPT>
        <SCRIPT>
        $(document).ready(function(){ 
            if (window.console)
                console.log('doc ready');
            var f=$("#m4_ifr_entity");  
            f.bind('load', function() {
               if (window.console)
                    console.log('iframe loaded');
                // do some stuff here
            });     
        });
        </SCRIPT>
        <META charset=utf-8>
    </HEAD>
    <BODY contentEditable=true>
        <DIV style="WIDTH: 800px; FLOAT: left; HEIGHT: 600px">
            <IFRAME id=m4_ifr_entity height="100%" src="/main.aspx?etn=account&amp;pagetype=entityrecord" width="100%"></IFRAME>
        </DIV>
    </BODY>
</HTML>

当执行“预览”时,console.log() 都出现在控制台中。都很好。

但是,当我将此网络资源作为 “导航链接” 添加到实体中,然后转到实体并单击导航中的链接时,浏览器控制台中只出现第一个 console.log(),而f.bind('load'... 内部的其他 console.log() 不存在,所以我认为 IFRAME 加载事件根本不会被触发。 IFRAME 本身加载得很好。

当我将调试器附加到 javascript 时,我看到 f.bind('load', function() { 已到达,但调试器没有介入。

我在控制台中没有看到任何错误。我做了网络资源的“发布”。在 IE 9 和 IE 11 中尝试过。

问题是:为什么 jQuery f.bind('load'... 在第二个用例中没有执行?

【问题讨论】:

    标签: jquery iframe dynamics-crm-2011 dynamics-crm onload


    【解决方案1】:

    由于您已经处于不受支持的领域,您可能希望进入 html Web 资源的父窗口(如果存在)并调用某些函数。

    在 html 网络资源中:

    function onPreviewLoaded(){
    //do something
    }
    

    以javascript形式:

    function onFormLoad(){
    if(parent && parent.onPreviewLoaded)
    parent.onPreviewLoaded();
    }
    

    【讨论】:

    • 感谢您的努力。我发现 mu “load” 处理程序在第二个用例中绑定得太晚了 - 我在答案中添加了详细信息。
    • @IvanJovovic,很高兴你知道了!
    【解决方案2】:

    原来这是由于在 IFRAME 已经加载后绑定到加载事件,因此事件处理程序永远不会执行。

    有两种可能的修复方法:

    onload 放入 IFRAME html 中:

    <IFRAME onload="someJsHere()"
    

    或者在onload绑定后强制重新加载IFRAME src(这个在src通过javascript动态添加到IFRAME时也很有用):

    f.bind('load', function() {
        if (window.console)
           console.log('iframe loaded');
           // do some stuff here
        });
    f.attr('src', f.attr('src'));
    

    【讨论】:

    • 您好,如何将 onload 添加到 CRM 生成的 IFRAME 元素中?
    猜你喜欢
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    • 2014-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    相关资源
    最近更新 更多