Iframe element cannot be retrieved from eventListener load

Asked 1 years ago, Updated 1 years ago, 27 views

If you set the event listener in load, getElementsByTagName will not take the iframe element.
What should I do?iframeDoc is a global variable.

window.addEventListener('load', async function(){
 let iframeBody = document.getElementsByTagName('iframe')[0].contentDocument.body;
 
 observer.observe (iframeBody, config);
 });

javascript

2022-09-30 19:37

1 Answers

Because the js file was loaded in iframe, the document itself pointed to the document in iframe.So I was looking for an iframe in iframe that does not exist in the above code.
—— From Comments

That's right.


2022-09-30 19:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.