Auto convert keywords into links

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Auto convert keywords into links



Is there a simple way to auto-convert keywords on article pages into internal hyperlinks? Maybe using a text file with a list of all keywords i want to auto convert, so that any occurance of those keywords in an article page are automatically converted into links? First occurance of any keyword only. This is for a simple static html site. Thanks for any help.


<script type="text/javascript">
var searchFor = 'revolution'; // replace with search phrase
var linkTo = 'revolution.html'; // replace with URL
var caseSensitive = false; // set to true or false (without quotes)
// do not change script below this line
var content = document.getElementsByTagName('body')[0];
var flag = caseSensitive ? '' : 'i';
var pattern = new RegExp("\s(?!</a>)(" + searchFor + "\b)", "g" + flag);
content.innerHTML = content.innerHTML.replace(pattern, " <a href='" + linkTo + "'>$1</a>");
</script>





But where's the attempt?
– techfoobar
Apr 19 '13 at 14:06





Have tried this.. <script type="text/javascript"> var searchFor = 'revolution'; // replace with search phrase var linkTo = 'revolution.html'; // replace with URL var caseSensitive = false; // set to true or false (without quotes) // do not change script below this line var content = document.getElementsByTagName('body')[0]; var flag = caseSensitive ? '' : 'i'; var pattern = new RegExp("\s(?!</a>)(" + searchFor + "\b)", "g" + flag); content.innerHTML = content.innerHTML.replace(pattern, " <a href='" + linkTo + "'>$1</a>"); </script> Only has one keyword, and links all occurrences.
– user1658495
Apr 19 '13 at 14:31





Any help anyone?
– user1658495
Apr 19 '13 at 19:13




2 Answers
2



I also found this answer - looks like it's exactly what you're trying to do here:



make keyword into link automatically, globally





Check the jquery near the bottom -here's a working example too! jsfiddle.net/andrewwhitaker/VmHjJ
– user3338845
Feb 21 '14 at 20:31





how to convert two different keywords in to two different link






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results