Google Groups

Re: how to get elements in iframe


jinqi.yin Sep 10, 2007 12:07 AM
Posted in group: greasemonkey-users
Thanks for all your help

it is now worked.
after read the article of the pitfall ,[1]
i modified my code .
i changed the code from
setTimeout('outlinksframe()',3000);
to
setTimeout(outlinksframe,3000);

thanks to every one in this group.

[1] article: http://www.oreillynet.com/lpt/a/6257

On Sep 10, 2:30 pm, "jinqi.yin" <jinqi....@gmail.com> wrote:
> hi Vectorspace
>
> > So, frames[j].document.getElementsByTagName(...) should work.
>
> i dosenot work in my browser .
>
> jinqi
>
> On Sep 10, 2:12 pm, Vectorspace <vectorsp...@ntlworld.com> wrote:
>
> > contentDocument is limited, in my experience. But you were half way
> > there already.
>
> > You were using frames[j].getElementsByTagName(...)
>
> > As if the frame object was the equivalent of the document object - it is
> > not. The frame object is the equivalent of the window object.
>
> > So, frames[j].document.getElementsByTagName(...) should work.
>
> > jinqi.yin wrote:
> > > Hi Vectorspace
> > > yes ,i access the  same domain as the parent page.
>
> > > but i found that  i use the wrong property ,'contentDocument' is the
> > > right property of iframe. after changed it to this correct property,
> > > i get the iframe content. but a new problem arise , that is before
> > > all of the contents of iframe loaded in , the g.m. already finished.
> > > that means i could not get all the contents of the iframe by the
> > > g.m.
>
> > > i think there will be at least 1 method to solve this,
> > > set a timer to control the g.m. script to run.
> > > but , an  undefined function error occured .
> > > is that mean g.m. only run at once the page loaded in?
>
> > > thanks
> > > jinqi
>
> > > On Sep 7, 10:47 pm, Vectorspace <vectorsp...@ntlworld.com> wrote:
>
> > >> You can only access the contents of a frame if the frame is from the
> > >> same domain as the parent page.
>
> > >> E.g. If the page iswww.google.com/andtheframe iswww.google.com/preferencesthenitwill work.
> > >> If the page iswww.google.comandtheframe iswww.microsoft.comthenit
> > >> won't work.
>
> > >> Cross-site scripting (javascript on one page accessing the contents of
> > >> another page on a different domain) is disabled in Firefox for security.
>
> > >> jinqi.yin wrote:
>
> > >>> i try to get elements in iframe , it doesn't work.
> > >>> the code seems like this .
>
> > >>> function outlinksframe(){
> > >>>  if(!document.getElementsByTagName("iframe")) return;
> > >>>  var iframes = document.getElementsByTagName("iframe");
> > >>>  for(var j=0; j<iframes.length; j++){
> > >>>  if(iframes[j]){
> > >>>  if(iframes[j].getElementsByTagName("form")){
> > >>>  var form11 = iframes[j].getElementsByTagName("form");
> > >>>  form11.action = "";
> > >>>  form11.target = "_blank";
> > >>>  }
> > >>>  }
> > >>>  }
> > >>> }
> > >>> outlinksframe();
>
> > >>> yours
> > >>> jinqi