简体   繁体   English

DOMContentLoaded在DOM上 <object> 在Edge中不起作用

[英]DOMContentLoaded on DOM <object> doesn't work in Edge

To get the DOMContentLoaded event of an included object like this 要获取包含对象的DOMContentLoaded事件,如下所示

<object class="emb" data="./probe-object.html" width="100" height="100" type="text/html">

works in Chrome and Firefox with the following code, but not Edge. 可以在Chrome和Firefox中使用以下代码运行,但不能使用Edge。

let includedObject = document.querySelector(".emb object");
includedObject.contentWindow.addEventListener('DOMContentLoaded', function() {
    includeObject();
});

How can I do something similar in Edge? 如何在Edge中做类似的事情?

Try to modify your code like this: 尝试像这样修改您的代码:

let includedObject = document.querySelector("object.emb");
includedObject.addEventListener('DOMContentLoaded', function() {
    includeObject();
});

Check you console. 检查您的控制台。 I guess you find usefull error about this. 我想您会发现有用的错误。

The selector was not correct, so I guess, it generate an undefined contentWindow error. 选择器不正确,所以我猜想它会生成未定义的contentWindow错误。 This contentWindow used for iframe objects and you has only an object tag. 该contentWindow用于iframe对象,并且只有一个对象标签。

If 如果

   includedObject.contentWindow.addEventListener

is replaced with 被替换为

   includedObject.contentDocument.addEventListener

it works in Edge, but not in Edge nor Firefox. 它适用于Edge,但不适用于Edge和Firefox。 This seems like an Edge bug. 这似乎是一个Edge错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM