Hello,
i have an website with many subpages, i want certain words to link to certain pages sitewide:
SEO -> [noparse]http://mydomain.com/seo/[/noparse]
Web Hosting -> [noparse]http://mydomain.com/webhosting[/noparse]
Programming -> [noparse]http://mydomain.com/programming[/noparse]
i mean i dont want to edit source code to add hyperlinks, but i want javascript to convert these words to links (case insensitive)
Please can you share the script which will do this? I have ZERO knowledge in javascript
So far i found these:
#1 source: http://bavotasan.com/2010/jquery-replace-word-with-link/
A) Add into header
<scripttype='text/javascript'src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
B) Add into footer
<script type="text/javascript"> (function($) { var thePage = $("body"); thePage.html(thePage.html().replace(/jQuery/ig, '<a href="http://jquery.com">jQuery</a>')); })(jQuery) </script>
but this is only for one word, and also requires jquery, which is quite largeā¦
#2 source: http://stackoverflow.com/questions/1583303/search-for-words-replace-with-links/1583362#1583362
var replacementDict ={'foo':'http://www.foo.com/','bar':'http://www.bar.net/'};var theRegex =/\\b(foo|bar)\\b/g;
theText.replace(theRegex,function(s, theWord){return"<a href='"+ replacementDict[theWord]+"'>"+ theWord +"</a>";});
(this means i need to add this into my header.php somehow?
Hope someone can come with a solution / advice on how to achieve that? Thank You