0

I am providing users with a textarea into which to input descriptions of their products. I am also allowing people to comment on the products like on Facebook.

Sometimes these posts include a URL to further information and I would like to be able to detect that part of the text as a URL and wrap it in an anchor <a> element once it is published to the page.

The text is being submitted by a form and goes to the server as plain text. I use a REReplace() regex replace function on the server-side to convert carriage returns into <br> tags so that it looks correct on the page.

However I don't know how to parse out the URL parts and wrap them in an anchor tag. Should it be done on the server-side or should I use jQuery on the client-side to wrap URLs on the fly? If I do it on the fly and there's hundreds of comments on the page with URLs - wouldn't this affect the page's performance?

If its on the server-side whats the best way to do it? I have jSoup on the server but couldn't work this one out because no HTML gets submitted from the textarea - only plain text e.g.

This new TV features 4K HDR technology. Read more at http://www.google.com

UPDATE: This is not a duplicate question of others. I am not asking how to convert plain links on a webpage into working ones (I can use linkify for that).

I am asking how to linkify on the server-side using jSoup or something similar. The textarea does not pass any HTML code to the server and neither can I wrap the text in anchor element because its a textarea and the inserted text doesn't appear in the DOM from what I can tell using Firebug.

volume one
  • 6,800
  • 13
  • 67
  • 146

0 Answers0