Jump to content

How to make certain words an automnatic link?


pioneerx01

Recommended Posts

Lets say that I want to make a certain word (or words) on a page a link. How would I make it a link without having to code in a link.

 

Some site have adds on certain words; one day and not the next day. I am looking for similar feature, but less intrusive. No pop-up, just a link.

I can not seem to be able to get it to work. Where exactly should I place this code. I tried both in header and body, but none works.

 

I am new to PHP, but what exactly defines "$content" Would I have to recode my paragraphs as

$content = paragraph Chicken paragraph;
echo "$content";

Im assuming $content is the content (text you want auto links generated from) before it is output on the screen. However I guess your website isn't set up that way.

 

Doesn't matter, because you can do it in Javascript anyway ^^ . Have a look at http://stackoverflow.com/questions/1774269/auto-link-specific-words-and-phrases and http://psoug.org/snippet/Javascript-Auto-Link-words_113.htm

Hi,

 

I have looked at both links (as thoroughly as I know how) but I can not get either working. I know nothing about Javascript, which is probably why I can not get it to work.

 

<html>
<head>
<script type="text/javascript">
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;
  }
}
</script>
</head>
<body>
<p>Check out these cables!</p>
</body>
</html>

 

Where do I place:

 

'cables':'http://www.google.com',

 

to make cables as hyperlink to a site (Google in this example)?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.