refer to text of url

L

Lars Vatland

How can I access the text of an url via javascript, ie. get 'foo' (and
send it as parameter in goto(), in example:

<a href="javascript:goto([foo])">foo</a>

Or refer to it globally?

document.links.href.text.value ?
this.href.text ?
 
L

Lars Vatland

I want to refer to the part between <a> and </a> in an url - the text
accompanying the url. Is it possible?


Can you clarify what you mean by accessing the text of a URL?

Lars Vatland said:
How can I access the text of an url via javascript, ie. get 'foo' (and
send it as parameter in goto(), in example:

<a href="javascript:goto([foo])">foo</a>

Or refer to it globally?

document.links.href.text.value ?
this.href.text ?
 
A

Andi B

I dont honestly know - however, if you do as you have done in your example,
by putting the text you want to sent as a parameter already, it should
work - the only problem is that you do have to type the text each time.

Lars Vatland said:
I want to refer to the part between <a> and </a> in an url - the text
accompanying the url. Is it possible?


Can you clarify what you mean by accessing the text of a URL?

Lars Vatland said:
How can I access the text of an url via javascript, ie. get 'foo' (and
send it as parameter in goto(), in example:

<a href="javascript:goto([foo])">foo</a>

Or refer to it globally?

document.links.href.text.value ?
this.href.text ?
 
L

Laurent Bugnion, GalaSoft

Hi,

Lars said:
How can I access the text of an url via javascript, ie. get 'foo' (and
send it as parameter in goto(), in example:

<a href="javascript:goto([foo])">foo</a>

Or refer to it globally?

document.links.href.text.value ?
this.href.text ?

The text of a link should, according to the Netscape doc, be accessible with

linkInstance.text;

However, there doesn't seem to be a way to identify a link namely. Of
course you can always use the links array, but working with indexes is
not good programming practice, except in loops of course.

alert( document.links[2].text );

It seems, however, to be the only way.

Note also that this fails in IE, which doesn't seem to recognize the
property "text" of the Link instance (alerts "undefined").

HTH,

Laurent
 
E

Evertjan.

Laurent Bugnion, GalaSoft wrote on 16 aug 2003 in comp.lang.javascript:
Note also that this fails in IE, which doesn't seem to recognize the
property "text" of the Link instance (alerts "undefined").

IE6:

<a href='' onclick="alert(this.innerText);return false">Text alert</a>
 
L

Lars Vatland

Ok, thanks, I use

<a href='' onClick="q(this);return false">foo</a> bar<br>

(..and if else on this.text / this.innerText).

Is there a shorthand for 'return false', or avoid it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top