How to access parent iframe elements from a child javascript page?

后端 未结 6 2153
说谎
说谎 2020-12-19 02:55

I have 2 pages: Parent and child.

In the parent page I have an iframe whose value I want to fetch in the JavaScript of child page. Is there any way?....Please suggest

6条回答
  •  无人及你
    2020-12-19 03:32

    Use

    parent.getElementById('elementId').value;
    

    to get the element. If you have multiple nested iframes, you can get the root parent by using

    top.getElementById('elementId').value;
    

    Either will work in your case.

提交回复
热议问题