Automatic hyperlink of each occurrence of a certain word (or sequence of words) to a predefined URL (not ambiguous); but do not show full URL

Similarly: Word search, replacement for links . However, I would prefer that the full hyperlinks are not displayed, but instead only the kind of hyperlink visible to the end user appears. --- I also can’t understand how to use the replace()-JS function, as used in the following message: How to replace all occurrences of a string in JavaScript? , on the same specific issue. --- Also similar to the JS question: Link to pages on Wikipedia articles in pure JavaScript , but I think that the answer, which cannot be, is ahead, to differentiate between ambiguous terms.

How do I automatically link each occurrence of individual words or sequences of words to their respective predefined URLs?

In (a) certain HTML page (s), is it possible to:

  • To predefine manually; or automatically (Cf: Wiki-api ) a list of individual words and their corresponding (ic Wikipedia) archives;
  • so that each (such related) word in the document automatically receives a predefined link to the corresponding (ic Wikipedia) article.

Example:

(1) Wherever a phrase occurs, this word should get a link: ... wiki / cell to give the following result: a cell is cell .


So, I really would like to imitate what actually happens in any Wikipedia article (although I don’t know if it is automated there).

Any help would be greatly appreciated.

+1
1

, , , . , , :

var words = [
    { word: 'foo', link: 'http://www.something.com' },
    { word: 'Something Else', link: 'http://www.something.com/else' ]
];

, , , , . , , .

$(function() {
    $.each(words,
        function() {
            var searchWord = this.word;
            var link = this.link;
            $('body:contains("' + searchWord + '")').each(function() {
                var newHtml = $(this).html().replace(searchWord, 
                    '<a class="wikilink" title="here is a link to Wikipedia" href="'+link+'">' + searchWord + '</a>');
                $(this).html(newHtml);
            });
        }
    );
});

: http://jsfiddle.net/yxhk1fcd/10/

+2

All Articles