Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access div in iframe parent

I have a page which contains an iframe to another page, what I am looking for is to click something inside the iframe, which can then access or more specifically hide a div in the parent. I know some JQuery but for some reason just sit there blankly at the code editor when I try to write it on my own

like image 890
Andrew Morris Avatar asked Jul 30 '12 08:07

Andrew Morris


People also ask

Can iframe access parent document?

To access elements of parent window from iframe with JavaScript, we can use the window. parent. document property to get the parent window's document.

Can iframe access parent windows?

The window will get opened by using the iframe, and the communication could be done with the parent window from the child window. To call a parent window function, use the following syntax and also refer to the code given below.

How do I access elements in an iframe?

Getting the element in IframegetElementById() method by passing iframe id as an argument. const iframe = document. getElementById("myIframe"); Now, it has and contentWindow property which returns the document object by using that we can access the elements from an Iframe.

Can iframe call function in parent?

This method safely enables cross-origin communication. And if you have access to parent page code then any parent method can be called as well as any data can be passed directly from Iframe.


1 Answers

try this in iframe:

$('#DIVtobehidden', window.parent.document).hide();
like image 84
ehmad11 Avatar answered Oct 14 '22 11:10

ehmad11