How might I access frames within the document?

30 views
Skip to first unread message

canadaduane

unread,
Nov 1, 2008, 6:11:40 PM11/1/08
to ubiquity-firefox
Hi all,

How would I go about accessing the frames within a website? The
following doesn't seem to work for me:

var tab = Application.activeWindow.open(Utils.url(url));
var $ = jQuery(tab.document.body);
$.find("frame[name=body]").html("DUANE WAS HERE");

Any ideas?

Thanks,
Duane Johnson

Blair McBride

unread,
Nov 2, 2008, 12:51:19 AM11/2/08
to ubiquity...@googlegroups.com
Your code for accessing frames isn't the issue there - you need to wait
until the page is loaded before doing anything with it.

Try the following modification:

var tab = Application.activeWindow.open(Utils.url(url));
tab.events.addListener("load", function() {
jQuery("frame[name=body]", tab.document).html("DUANE WAS HERE");
});

Hope that helps.


- Blair

canadaduane

unread,
Nov 2, 2008, 11:22:03 AM11/2/08
to ubiquity-firefox
It turns out that I am already doing the "addListener" bit (while
shortening my program for the email, I missed that part). Sorry to
add confusion!

Is there anything else that would prevent the frame DOM from being
accessed? Do I need a second level of listeners, i.e. to listen for
each frame's DOM to be loaded?

Blair McBride

unread,
Nov 7, 2008, 9:17:16 PM11/7/08
to ubiquity...@googlegroups.com
Oh, yes, you'll need to listen for the "load" event on whichever frame
you wish to modify too.

Warning: You may or may not have problems relating to cross-domain
scripting. Check the error console's messages.

- Blair

canadaduane

unread,
Nov 8, 2008, 11:46:53 AM11/8/08
to ubiquity-firefox
Thanks for your help on this, Blair. Do you know where I attach the
frame's load event? Would the code look something like:

tab = Application.activeWindow.open(Utils.url(url));
tab.events.addListener("load", function() {
tab.document.frames[0].events.addListener("load", function() {
// do stuff
});
});

I'll have to fiddle with things to see if that's correct. If you know
the answer directly, that would be helpful too.

Thanks again!
Duane

Blair McBride

unread,
Nov 9, 2008, 12:23:26 AM11/9/08
to ubiquity...@googlegroups.com
I haven't tested it, but with one small modification it should work:

tab = Application.activeWindow.open(Utils.url(url));
tab.events.addListener("load", function() {

tab.document.frames[0].addListener("load", function() {


// do stuff
});
});


- Blair

Reply all
Reply to author
Forward
0 new messages