SoFunction
Updated on 2025-03-01

Use jquery/js to get the iframe parent-child level and the same level to get elements

In web development, iframes are often used, and it is inevitable that you will encounter elements in iframes in parent windows, or elements in iframe frames that need to use elements in parent windows, or elements in parent windows in iframe frames

js

Get elements in iframe in parent window

1、

Format: ["iframe's name value"].("Id of the control in iframe").click();

Example: ["ifm"].("btnOk").click();

2、

Format:

var obj=("iframe's name").contentWindow;
var ifmObj=("Id of the control in iframe");
();

Example:

var obj=("ifm").contentWindow;

var ifmObj=("btnOk");

();

Get the element of the parent window in an iframe

Format: ("Element ID of parent window").click();

Example: ("btnOk").click();

jquery

Get elements in iframe in parent window

1、

Format: $("#iframe ID").contents().find("Control ID in#iframe").click();//jquery method 1

Example: $("#ifm").contents().find("#btnOk").click();//jquery method 1

2、

Format: $("Control ID in#iframe",("frame name").document).click();//jquery method 2

Example: $("#btnOk",("ifm").document).click();//jquery method 2

Get the element of the parent window in an iframe

Format: $('#Element ID', in parent window).click();

Example: $('#btnOk', ).click();

The above article uses jquery/js to obtain iframe parent-child level and simultaneous level elements is all the content I share with you. I hope you can give you a reference and I hope you can support me more.