I need pure JavaScript to use an array of specified words and URLs to read a webpage and convert any matching words into links. The Google Gods have neglected to return any helpful examples:( Any help would be great!
I found this on a site somewhere :
FUNCTION linkWord(obj){
FOR(i IN obj){
VAR x = document.body.innerHTML;
VAR linkStart = '<a href="'+obj[i]+'">';
VAR linkEnd = '</a>';
VAR reg = NEW RegExp ('\\b' + i + '\\b','g');
x = x.replace(reg, linkStart + i + linkEnd);
document.body.innerHTML = x;
}
}
linkWord ({
'funny':'http://www.example.com',
'another':'http://icant.co.uk'
});
Study it. Work out why yours didn’t work.