What is the way to access an IFrame element using the Prototype $ method

Using js prototype library I can access elements using $(elementID) . I can access an element in an iframe using

 $('iframeID').contentWindow.document.getElementById('ID of element inside Iframe'). 

I would like to use the same dollar method for my iframe to access elements in an Iframe. Is there any way?

+4
source share
2 answers

If you want to know the method, you can visit the link (after the search I received the link)

http://www.ruby-forum.com/topic/146705

and for the demo you can visit here

http://sandbox.equawire.com/stackoverflow/DollarIFrame3.aspx

Thanks.

0
source

You could write an iframe alias with something like:

 var $IFRAME = function (id){ return $('iframeID').contentWindow.document.getElementById(id); } 

Then say that you want to get the innerHTML of the element in this frame with id 'p1', which you could do:

 var x = $IFRAME('p1').innerHTML; alert(x); 

Or, to manipulate it, for example, hide it, you would do:

 $IFRAME('p1').hide(); 

The function name $IFRAME for the function is arbitrary on my part, you can call it getElementInsideIFrameID or any other calls to you.

+4
source

Source: https://habr.com/ru/post/1298971/


All Articles