Invoking JavaScript code in an iframe from the parent page

后端 未结 17 1820
栀梦
栀梦 2020-11-21 07:00

Basically, I have an iframe embedded in a page and the iframe has some JavaScript routines I need to invoke from the parent page.

Now the o

17条回答
  •  时光说笑
    2020-11-21 07:28

    Just for the record, I've ran into the same issue today but this time the page was embedded in an object, not an iframe (since it was an XHTML 1.1 document). Here's how it works with objects:

    document
      .getElementById('targetFrame')
      .contentDocument
      .defaultView
      .targetFunction();
    

    (sorry for the ugly line breaks, didn't fit in a single line)

提交回复
热议问题