Skip to main content
December 9, 2009
Frage

cfoutput text with clickable URL

  • December 9, 2009
  • 2 Antworten
  • 1108 Ansichten

Hi all,

I have a cfoutput that is displaying text from a database (Users enter text in a form that inputs it into a DB). As part of this entry, users can enter text including any url. However, when I output the results of what has been entered, the URLs are not clickable. The links can be anywhere in the forum post. (ex. "Check this out http://www.google.com" or "http://www.google.com Check this out")

How do I output text that may or may not include a URL and have that URL be clickable?

Thanks in advance!

Dieses Thema wurde für Antworten geschlossen.

2 Antworten

December 13, 2009

I have found several articles related to javascript and searching for URLs to convert to links, but am unsure on how to implement these with cfoutput.

Another thought would be to convert the text input to html. Is there a way to have the form create html from text. Or does the rich text editor insert what is entered as html?

My thought here is to get the html in, and it will be easier to output.

December 14, 2009

Okay, I have made some progress but not quite there. I am using REReplace with the my outputted variable (I found this regex online). It finds http:// and https:// and they link perfectly... but does not make www. a working link. The www. will be highlighted as a link, but it does not put the http:// in front of it. Here is my code:

<p>#REReplace(my.variable,"((((https?:)\/\/)|(www\.))[-[:alnum:]\?%,\.\/&##!@:=\+~_]+[A-Za-z0-9\/])", "<a href=""\1"" target=""_blank"">\1</a>", "ALL")#</p>

Any help is appreciated (and any easier methods is more appreciated!)

Inspiring
December 14, 2009

I am not sure the below helps you. Can you please try with the following options?

1) Use HTMLEditFormat or HTMLCodeFormat.

2) Try to use replace command while selecting the column in the database query itself and checking with <cfoutput>.

Thanks,

Satheesh.

ilssac
Inspiring
December 9, 2009

If you want a browser to display a URL as a clickable link, that URL must be inside a properly formated <a>nchor tag.  If your users are just entering URLS in the text, and not anchor tags you have two choices.

Train your users to enter proper anchor tags in the data.

Create a processor that will find the url's in the text and dynamically build a URL around it.

The latter is probably easier, but it is not trival.  Your best hope would be to find some code where somebody has already done this for you.  CFLIB [http://www.cflib.org/] is a great place to try first.