开发者

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

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

$('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 Iframe. Is there any way?


You could alias calling that iframe with something like:

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

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

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

Or to manipulate it, for example hide it, you'd do:

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

The $IFRAME name for the function is arbitrary on my part, you could call it getElementInsideIFrameID or whatever appeals to you.


If you are eager to know the method, you can visit the link (after searching I got the link)

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

and for the demo yo can visit here

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

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜