jQuery Plugin To Transform URLs In Text Into Links - linkify

jQuery Plugin To Transform URLs In Text Into Links - linkify
File Size: 1.12 MB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

linkify is a JavaScript plugin which can be used to automatically transform valid URLs and email addresses in text into clickable links.

See also:

Install & Download:

# Yarn
$ yarn add linkifyjs

# NPM
$ npm install linkifyjs --save

Basic Usage:

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

<script src="jquery.min.js"></script>
<script src="linkify.min.js"></script>
<script src="linkify-jquery.min.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 and done.

$(function(){
  $('p').linkify();
});

4. Or using data-linkify attribute.

<body data-linkify="p" data-linkify-target="_blank">
<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. All default plugin settings.

$('p').linkify({

  // additional attributes for the links
  attributes: null,

  // default CSS class
  className: 'linkified',

  // default protocol
  defaultProtocol: 'http',

  /* event listeners
    click: function (e) {
      alert('Link clicked!');
    }
  */
  events: null,

  // format the text
  format: function (value, type) {
    return value;
  },

  // format the href
  formatHref: function (href, type) {
    return href;
  },

  // ignore specified HTML tags
  ignoreTags: [],

  // if true, \n line breaks will automatically be converted to <br> tags.
  nl2br: false,

  // 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
  tagName: 'a',

  // target attribute for each linkified tag.
  target: {
    url: '_blank'
  },

  // custom validation rules here
  validate: true

});

Changelog:

v2.1.8 (2019-01-30)

  • Allow mentions with inner @ sign for federated mentions
  • Drop official support for Internet Explorer 8 and Node.js 6 (still supported unofficially but may break in future releases)
  • Update dev dependencies

v2.1.7 (2018-03-06)

  • update

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.