My content sometimes include URL for example in that URL(http://mobile.yazilimsozluk.com/konudetail.htm?9748) content a URL but it is not clickable. How can I do this clickable with javascript or css?Data come from API,I can not fix it.I must fix that in view with CSS or jquery
Asked
Active
Viewed 905 times
0
-
You can put you link inside URL and this will make it a clickable link – HenryDev Nov 12 '16 at 21:42
-
1Possible duplicate of http://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links – br3t Nov 12 '16 at 21:43
-
Please provide an example as per [mcve] – charlietfl Nov 12 '16 at 21:45
1 Answers
-1
Try this:
(function($) {
$(document).ready(function() {
$('div').html($('div').html().replace(/(https?:\/\/.+?)(?:\s|$)/ig, '<a href="$1">$1</a> '));
});
})(jQuery);
This searches all DIV content for URLs and replaces them by a corresponding anchor tag. Please note that the RegExp is very simple and needs optimization before being used in production.

Quagaar
- 1,257
- 12
- 21
-
thanks @Quagaar it works but it add end of url http://mobile.yazilimsozluk.com/konudetail.htm?9748 you can click here to see at the end of url – user1688401 Nov 12 '16 at 22:08
-
@user1688401 This is only an example and has to be adapted to your specific requirements. You should narrow down the set of processed elements to only match the ones containing the content to modify. Also remember to optimize the RegExp that detects the URLs. – Quagaar Nov 12 '16 at 22:28
-
Perhaps these can also be helpful to you: http://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links – Ren Nov 12 '16 at 22:50