Page 1 of 1
Facing a problem grabbing some Gmail related data
Posted: Tue Oct 21, 2008 2:54 pm
by legend986
Hi,
I have tried a simple thing in Firebug:
Code: Select all
var te = document.getElementsByName('subject');
for(var i in te) {
document.write(te[i]);
}
And then it simply prints:
Code: Select all
0function item() { [native code] }function namedItem() { [native code] }
I don't understand how to grab the text value of the subject field... Could someone please help me out?
Re: Facing a problem grabbing some Gmail related data
Posted: Tue Oct 21, 2008 3:38 pm
by Syntac
Assuming the subject field has an ID specified ("subj" in this example, although I'm pretty sure it's actually ":m2"), you can use:
Code: Select all
document.write( document.getElementById( "subj" ).value );
Although I don't see why this would work and getElementsByName() wouldn't.
In what context is this code being used?
Re: Facing a problem grabbing some Gmail related data
Posted: Tue Oct 21, 2008 4:07 pm
by VladSun
AFAIK, JavaScript for-each is for iterating properites of an object, not elements of an array.
You need something like:
[js]var te = document.getElementsByName('subject'); for(i=0; i< te.legth; i++) { document.write(te.innerHTML);}[/js]
Re: Facing a problem grabbing some Gmail related data
Posted: Tue Oct 21, 2008 5:07 pm
by legend986
@Syntac: Thanks a lot... The problem is that it doesn't show anything... I mean it shows in firebug that the command is being executed but it doesn't print anything... The id value was :ms
As for the purpose, I am trying to develop a firefox extension for myself to keep track of the people whom I am emailing in a text file along with the subject line.
@VladSun
Thanks... I used even that but that wasn't printing anything either... It shows that it has grabbed a HTML Object but doesn't show anything when I ask it to print something... Any other advice please?
Re: Facing a problem grabbing some Gmail related data
Posted: Wed Oct 22, 2008 3:00 pm
by legend986
Someone please?
Re: Facing a problem grabbing some Gmail related data
Posted: Wed Oct 22, 2008 3:01 pm
by VladSun
What are you parsing - an HTML or a XML document?
Show the source code.
Re: Facing a problem grabbing some Gmail related data
Posted: Wed Oct 22, 2008 3:07 pm
by legend986
Oh... Its Gmail itself... I mean the page that shows up when I hit the Compose Mail link after logging into Gmail... I am just trying to hook up some code so that I can grab the subject line when I click on the Send button and save it into a file.
Re: Facing a problem grabbing some Gmail related data
Posted: Wed Oct 22, 2008 3:15 pm
by VladSun
Oh, I see - it's a text input.
[js]var subject = document.getElementsByName('subject')[0].value;alert(subject);[/js]
Re: Facing a problem grabbing some Gmail related data
Posted: Wed Oct 22, 2008 3:18 pm
by legend986
Actually that is the problem. It keeps giving me this weird problem:
Code: Select all
TypeError: document.getElementsByName("subject")[0] is undefined
I thought I was accessing it correctly but this error leaves me with no clue...
Re: Facing a problem grabbing some Gmail related data
Posted: Wed Oct 22, 2008 3:24 pm
by VladSun
Google uses IFRAMEs - thats why you can't access directly from window.document
[js]alert(document.getElementById("canvas_frame").contentDocument.getElementById(':nz').value)[/js]
Re: Facing a problem grabbing some Gmail related data
Posted: Wed Oct 22, 2008 3:25 pm
by legend986
So if there anyway I can access these things? Do you have any suggestions please?
Re: Facing a problem grabbing some Gmail related data
Posted: Wed Oct 22, 2008 3:26 pm
by VladSun
I've just edited my post above

...
Re: Facing a problem grabbing some Gmail related data
Posted: Wed Oct 22, 2008 3:29 pm
by legend986
Ah.... Wonderful solution... Thanks a lot! Works like a charm
Perhaps the last thing that I should do is to hook up an onClick event to the Send button so that it can grab that data... I will now try that.. Thank You again...