iframe behaviour of onload vs addEventListener('load')

前端 未结 3 1863
南旧
南旧 2021-02-01 06:32

I\'ve been playing around with adding hidden iframe elements to a page, and I want to manipulate the DOM of the these once loaded. I\'ve noticed that I can\'t start manipulating

3条回答
  •  渐次进展
    2021-02-01 06:58

    Does the first example work? Not sure exactly what you're looking for, but this should illuminate when events work: jQuery document.ready source

    $(document).ready equivalent without jQuery

    addEventListener does not work in IE, so if that's where you're testing, then the 2nd would fail before the iframe gets appended.

    You could also add a callback from the page itself, though (for example, using jQuery so you don't reinvent the wheel) I suspect $(iframe).ready() {..} would give you consistent behavior.

提交回复
热议问题