Connecting Tech Pros Worldwide Forums | Help | Site Map

[Greasemonkey] Getting value between tags

Newbie
 
Join Date: Sep 2008
Posts: 3
#1: Sep 6 '08
What I got:
[HTML]<font color="#ffffcc" face="Tahoma, Arial, Helvetica" size="+1">testA</font>
<font color="#ffffcc" face="Tahoma, Arial, Helvetica" size="+1">test1</font>
[/HTML]

What I want:
[HTML]<font color="#ffffcc" face="Tahoma, Arial, Helvetica" size="+1">testA <a href="http://loginpage.php?login=testA">login</a></font>
<font color="#ffffcc" face="Tahoma, Arial, Helvetica" size="+1">test1<a href="http://loginpage.php?login=test1">login</a></font>
[/HTML]
Now I know how to insert the <a> tag but I can't get the "testA", "test1" values. Any help would be greatly appreciated .

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#2: Sep 6 '08

re: [Greasemonkey] Getting value between tags


first, drop the <font> tags, they're deprecated since you can do styling with css.

if you have say
[HTML]<span>test1</span>[/HTML]
you can use
Expand|Select|Wrap|Line Numbers
  1. {span}.firstChild.nodeValue
  2. {span}.value
  3. {span}.innerHTML
there are several ways to get the desired span object...

regards
Newbie
 
Join Date: Sep 2008
Posts: 3
#3: Sep 6 '08

re: [Greasemonkey] Getting value between tags


Quote:

Originally Posted by Dormilich

first, drop the <font> tags, they're deprecated since you can do styling with css.

if you have say
[HTML]<span>test1</span>[/HTML]
you can use

Expand|Select|Wrap|Line Numbers
  1. {span}.firstChild.nodeValue
  2. {span}.value
  3. {span}.innerHTML
there are several ways to get the desired span object...

regards

I have no acces to the page, that is why I need grease monkey
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#4: Sep 6 '08

re: [Greasemonkey] Getting value between tags


Quote:

Originally Posted by morbo

I have no acces to the page, that is why I need grease monkey

this will result in quite a bit of work. the main problem you have (without access to the page) is to address the right font tags. you probably have to get all font tags, check if they contain a link and then you can read the text.

maybe you can provide a link, so I can have a look at the html (this could make things easier).

regards
Newbie
 
Join Date: Sep 2008
Posts: 3
#5: Sep 6 '08

re: [Greasemonkey] Getting value between tags


http://www.hswn.dk/hobbit/servers/servers.html


What I am trying to accomplish is to have an icon next to the server names that connects to a login page and gives the server name as get variable.

ps: the span element is not in my version (runs on secure local network)
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#6: Sep 6 '08

re: [Greasemonkey] Getting value between tags


nasty bit of tree walking there....

ok, first you need the right table
Expand|Select|Wrap|Line Numbers
  1. var tbl = document.getElementsByTagName("table")[2]; // 3rd table
then select the table rows
Expand|Select|Wrap|Line Numbers
  1. var rows = tbl.childNodes; // tbl.firstChild.childNodes for IE
now get the font tags (loop through the rows) and the text
Expand|Select|Wrap|Line Numbers
  1. var text = rows[i].firstChild.getElementsByTagName("font")[0].firstChild.nodeValue;
I didn't test it, but I think it should work this way.

regards
Reply


Similar JavaScript / Ajax / DHTML bytes