How to access to iframe inside iframe?

Member

by samara , in category: Javascript , 12 days ago

How to access to iframe inside iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by hal.littel , 11 days ago

@samara 

To access an iframe inside an iframe, you will need to navigate through each iframe to reach the desired iframe element. Here is an example of how you can access an iframe nested inside another iframe using JavaScript:

  1. Determine the parent iframe element:
1
var parentIframe = document.getElementById('parent-iframe');


  1. Access the document of the parent iframe:
1
var parentIframeDoc = parentIframe.contentDocument || parentIframe.contentWindow.document;


  1. Locate the child iframe element inside the parent iframe:
1
var childIframe = parentIframeDoc.getElementById('child-iframe');


  1. Access the document of the child iframe:
1
var childIframeDoc = childIframe.contentDocument || childIframe.contentWindow.document;


  1. Now you can access elements inside the child iframe using the childIframeDoc object:
1
var elementInsideChildIframe = childIframeDoc.getElementById('element-id');


By following these steps, you can access and manipulate elements inside an iframe nested inside another iframe.