1

To get the DOMContentLoaded event of an included object like this

<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.

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

How can I do something similar in 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. This contentWindow used for iframe objects and you has only an object tag.

4

2 回答 2

1

If

   includedObject.contentWindow.addEventListener

is replaced with

   includedObject.contentDocument.addEventListener

it works in Edge, but not in Edge nor Firefox. This seems like an Edge bug.

于 2018-09-10T12:44:29.770 回答
0

尝试像这样修改您的代码:

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

检查你的控制台。我猜你会发现有用的错误。

选择器不正确,所以我猜它会生成未定义的 contentWindow 错误。此 contentWindow 用于 iframe 对象,您只有一个对象标签。

于 2018-09-04T10:23:52.757 回答