Blog

Here I am going to introduce one altogether useful plugin in jquery to Automatically convert plain text URLs into member using jquery. Some time you got text following lots of urls and you compulsion to automatically generate colleague from plain URLs for that defense that visitor can easily goto source site. Here i found plugin urlToLink vis–vis speaking github which past you to transforms URLs in text into HTML <a> elements.

Follow below steps to automatically convert plain text url’s into link using jquery

Include the latest report of jQuery library and jquery.urlToLink.min.js script in your html page.

<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  crossorigin="anonymous"></script>
<script src="jquery.urlToLink.min.js"></script>

Sample html paragraph considering some dummy URLs

<p style="width:70%; margin:0 auto;">
Lorem Ipsum ( http://lipsum.com ) is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. (http://example.com ) It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br/>
My Public NoteBook - http://www.findyoursolution.in
</p>

Finally call urlToLink to member show back suggestion to page and convert all plain text urls into partners.

<script>
$(function() {  
 $('p').urlToLink();
});
</script>

If you sore to right to use every friends in added version, you dependence to handily tallying together direct attribute in above sham see out cold example.

<script>
$(function() {  
 $('p').urlToLink({
   target : '_blank'
});
});
</script>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.