jQuery Plugin To Transform URLs In Text Into Links - linkify

jQuery Plugin To Transform URLs In Text Into Links - linkify

linkify is a jQuery plugin used to automatically transform valid URLs and email addresses in text into clickable links.

See also:

Basic Usage:

1. Include jQuery library and jQuery linkify plugin in the page.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="dist/jquery.linkify.js"></script>

2. A Linkified object contains a DOM node (or just plain text) whose inner text is replaced by HTML containing <a> links to URLs discovered in that text.

<p>My website is https://www.jqueryscript.net</p>
<p>My email address is [email protected]</p>

3. Call the plugin on the <p> elements.

<script>
$(window).on('load', function () {
$('p').linkify();
});
</script>

4. Or using data-linkify attribute.

<body data-linkify="p">
<p>My website is https://www.jqueryscript.net</p>
<p>My email address is [email protected]</p>
</body>
<! or -->
<p data-linkify="this">My website is https://www.jqueryscript.net</p>

5. Settings.

<script>
$(window).on('load', function () {
$('p').linkify({
tagName: 'a', // The tag that should be used to wrap each URL. This is useful for cases where a tags might be innapropriate, or might syntax problems
newLine: '\n', // The character to replace new lines with. Replace with "<br>" to space out multi-line user content.
target: '_blank', // target attribute for each linkified tag.
linkClass: null, // The class to be added to each linkified tag. The extra .linkified class ensures that each link will be clickable, regardless of the value of tagName.
linkClasses: [],
linkAttributes: { // HTML attributes to add to each linkified tag. In the following example, the tabindex and rel attributes will be added to each link.
tabindex: 0,
rel: 'nofollow'
} 
});
});
</script>

Change logs:

v2.1.7 (2018-03-06)

v1.1.7 (2014-08-06)

  • update

v1.1.6 (2014-05-15)

  • update

v1.1.5 (2014-05-14)

  • update

v1.1.4 (2014-04-10)

  • Added option for detecting ports

v1.1.3 (2014-01-19)

  • update to the latest version.

This awesome jQuery plugin is developed by SoapBox. For more Advanced Usages, please check the demo page or visit the official website.

  • Publication date: 06.03.2018
  • Source