javascript - What is the way to access IFrame's element using Prototype $ method - Stack Overflow

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

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?

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?

Share Improve this question edited Apr 9, 2013 at 7:33 acme 14.9k8 gold badges76 silver badges114 bronze badges asked Jan 21, 2010 at 7:15 NazmulNazmul 7,21812 gold badges53 silver badges64 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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./topic/146705

and for the demo yo can visit here

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

Thanks.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744581146a4582043.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信