mdn / dom-examples

Code examples that accompany various MDN DOM and Web API documentation pages
https://developer.mozilla.org/en-US/docs/Web/API
Creative Commons Zero v1.0 Universal
3.48k stars 1.81k forks source link

onload in iframe.contentWindow is not working ? #242

Closed liyoung1874 closed 10 months ago

liyoung1874 commented 10 months ago
// window is Window object, so
window.onload = () => {
    // This is working
}

// In this document, has a iframe, so
const iframe = document.getElementById('#myIframe')
const iframeWindow = iframe,contentWindow
// iframeWindow is Window object too.

iframwWindow.onload = () => {
    // This is not working.
}

Why is this ? Can explain ?

Thanks so much.

teoli2003 commented 10 months ago

Are you sure the dom is loaded when you call this. And that getElementById worked?

Also there is an incorrect comma in the declaration if iframeWindow.

Is it code copy-pasted from an example? If so which one?

liyoung1874 commented 10 months ago

Hello, this case is happening in my work. This code is my handwrite.

That incorrent comma and selector is my fault. Sorry.

Attach screenshot:

  1. html image
  2. js (vue) image
  3. debug log image
  4. my brower version image

Finally, please forgive my English expression.

teoli2003 commented 10 months ago

Sorry, I can't help you more, I don't know about Vue.

You may bring them of a Vue support forum.

We are short in ressources so we cannot do support, but thanks for thinking about us. I'll close this issue.

liyoung1874 commented 10 months ago

Thanks for your patient.

But i queit want to know the answer to this question.

So, i use another way to test the case.

There is screenshot.

image