Forum Moderators: open

Message Too Old, No Replies

FF extension

cant get to the frame im after..

         

natty

4:37 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



hi all,

prolly not the best place to post this, but im hoping one of you clever chaps(esses) can help me out.

im just writing (trying to write) a crummy FF extension to do some things with a form in a page.. nothing spectacular, just showing form elements and values/names/ids.
but....
as alot of the time the page i am wanting to get at, is in a frameset, but i cant seem to set the document so that i can get at everything with getElementById etc..

i start with


var doc = window._content.document;

which happily sets 'doc' to what is needed, but this only works with NO frames.

so i tried this (partially lifted from someone elses extension) but cant seem to get my head around exactly how to get there..

doc = findFrame(doc, /pagename\.asp/i);

findFrame is as follows


function findFrame(doc,regexp){
var frames = doc.getElementsByTagName("frame"),i;
if (frames.length > 0 ){
for (i=0;i<frames.length;i++){
if (frames[i].document.location.href.search(regexp) > -1){
return frames[i].document;
}
}
}else{
return doc;
}
}

but this doesnt really do the trick, in fact, it seems to just miss completely.
now, im wondering if its somethign to do with how i am invoking the extensions script.. and as it happens its from the RightClick menu.
but once i have set the document to the correct frame doc then i am away, and can go home.. :)

any help much appreciated..
nat

Fotiman

4:53 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




var frames = doc.getElementsByTagName("frame"),i;

What's that bit at the end there? Looks like a typo. Is this what you want:

var frames = doc.getElementsByTagName("frame");

Bernard Marx

4:55 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's OK. i is being declared as a variable.
Multiple declarations can be separated by commas.

natty

5:14 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



yeah, not sure i made my question obvious,

but when i use that little functon, the return value when it hits the loop is never actually useable, for getElementsById and things like that..

Fotiman

5:39 pm on Nov 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Instead of

var doc = window._content.document;

How about trying this:

var doc = top.document;