tags:

views:

180

answers:

1

AFAIK,I can achieve this goal by window.frames['frame_name']

but if I only know frame_id,is it possible to get the content too?

You can try it out here:

http://maishudi.com/rte-light-read-only/index.html

btw,is it possible to get location attribute through iframe_id?

I tried long ago but failed.

A: 

I think this should do it. It works on (the latest) firefox, safari, camino and opera (mac).
You should still do some testing though (especially in IE)

var iframeObj = document.getElementById("theIframeId");
var documentObj = iframeObj.contentWindow || iframeObj.contentDocument;
var location = documentObj.location.href; // I think this only works if
                                          // the content of the iframe comes 
                                          // from the same domain.
andi
I've tested it's not working.You can test it here :http://maishudi.com/rte-light-read-only/index.htmlusing :var iframeObj = document.getElementById("id_description");var documentObj = iframeObj.contentWindow || iframeObj.contentDocument;alert(documentObj) ;
Shore
I did some (local) tests and it works as expected.
andi
maybe IE?It failed in firefox.
Shore
did you wrap it in an load event? http://tinyurl.com/oy48ul - does this work?
andi
no,i just run that code in console of firebug.
Shore
it seems to work, even in ie (6 and 7)
andi
http://tinyurl.com/oy48ulthis works because you are using iframe_name,not iframe_id..
Shore
no, there were both methods tested. I edited it now and left only the one with contentWindow/Document
andi
oh,yes,it works!btw,is it possible to get location attribute through iframe_id?I tried long ago,but failed.
Shore
You can access the location object from documentObj.documentObj.location.href will give you the address. I think that there are some security issues here, and it can't be accessed if the content from the iframe is from a different domain.
andi