Facing a problem grabbing some Gmail related data

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Facing a problem grabbing some Gmail related data

Post 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?
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: Facing a problem grabbing some Gmail related data

Post 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?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Facing a problem grabbing some Gmail related data

Post 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]
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Re: Facing a problem grabbing some Gmail related data

Post 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?
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Re: Facing a problem grabbing some Gmail related data

Post by legend986 »

Someone please?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Facing a problem grabbing some Gmail related data

Post by VladSun »

What are you parsing - an HTML or a XML document?
Show the source code.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Re: Facing a problem grabbing some Gmail related data

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Facing a problem grabbing some Gmail related data

Post by VladSun »

Oh, I see - it's a text input.
[js]var subject = document.getElementsByName('subject')[0].value;alert(subject);[/js]
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Re: Facing a problem grabbing some Gmail related data

Post 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...
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Facing a problem grabbing some Gmail related data

Post 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]
Last edited by VladSun on Wed Oct 22, 2008 3:26 pm, edited 1 time in total.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Re: Facing a problem grabbing some Gmail related data

Post by legend986 »

So if there anyway I can access these things? Do you have any suggestions please?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Facing a problem grabbing some Gmail related data

Post by VladSun »

I've just edited my post above ;) ...
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Re: Facing a problem grabbing some Gmail related data

Post 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...
Post Reply