Re: Change Text into Links

Tech-Archive recommends: Fix windows errors by optimizing your registry



littleredhairedgirl wrote on 08 jul 2009 in
microsoft.public.scripting.jscript:

I have a page that loads some text into a div
What I'd link to do is (re)create each word into a link.

so loop thru each word in the div with innerHtml and wrapping it with
anchor tag


<script language="javascript" type="text/javascript">

Deprecated language code, from the last century

function linkWord(obj){
{

Why twice a { ?

sObj.link="http://groups.google.com/groups/search?q=";;

Do you use this in the function? I think not!

for(i in obj){

var x = document.body.innerHTML;

you should var-declare outside the loop

var linkStart = '<a href="'+ x +'">';

same

x is not an url, it is the innerHTML of body.

var linkEnd = '&btnG=Search&sitesearch=groups.google.com</a>';

so &btnG=Search&sitesearch=groups.google.com is the text to be clicked?

x = linkStart + x + linkEnd);
document.body.innerHTML = x;

And for every instance of the link you overwrite the whole body?


}

missing }

The function is not called.

</script>


I suppose you first learn the basics of Javascript.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
.



Relevant Pages

  • Re: Why does this not work properly?
    ... These are used to display a message using innerHTML. ... I built a simple loop to clear all fields: ... It fails and returns the error message: message: ... (My head still hurts from banging it against the wall!) ...
    (comp.lang.javascript)
  • Re: Adding list items to a DHTML List box
    ... > Now why do you have the following line inside the loop: ... > playing with innerHTML? ... I think that I tried createElement() but couldn't figure how to ... > when you're just going to reset the innerHTML at the end: ...
    (microsoft.public.vb.syntax)
  • Re: Why does this not work properly?
    ... These are used to display a message using innerHTML. ... I built a simple loop to clear all fields: ... the function fails. ...
    (comp.lang.javascript)
  • Re: Adding list items to a DHTML List box
    ... First, you should really use & to concatenate strings, not + ... Now why do you have the following line inside the loop: ... > Debug.Print listItem ... when you're just going to reset the innerHTML at the end: ...
    (microsoft.public.vb.syntax)
  • Re: Scanner class and last line in a file
    ... I can't repro the problem - help me understand what I'm missing. ... the following test class: ... And input file with no trailing newline created by: ... Then the second part of the for loop checks ...
    (comp.lang.java)