Hello, i have an website with many subpages, i want certain words to link to certain pages sitewide: SEO -> http:// mydomain.com/seo/ Web Hosting -> http:// mydomain.com/webhosting Programming -> http:// mydomain.com/programming 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> Code (JavaScript): 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> Code (JavaScript): 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>";}); Code (JavaScript): (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
For the second solution you just need to put the javascript inside a script-tag, like this: <script type="text/javascript"> 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>";}); </script> Code (markup): you can just place this in the footer, if you want
I tried to add above code into my page between <body> and </body>, but words was not turned into links
I didn't look at the actual code - I figured you actually copied a _working_ solution, not a rough draft. Did you even read the comment that followed the code on the stackoverflow-link? Read some more, and look at some of the other code-examples.
I don't think you have quite read his replies properly. He is only trying to help you, maybe you shouldn't act like you're actually paying him to do or something. And yes, he is right. Did you just copy that code into your page? Because that isn't going to work unless that's what your actually trying to replace. Post your actual website link or some code.
HuggyStudios: this topic become useless. i thought some will post solution. this topic is not about ME and solving MINE issue!!! This topic is about hundreds or thousands people reading it in future and saving their time. If you cant provide solution, than dont waste this topic space. thanks No solution yet