mark-external-links

1.0.3 • Public • Published

Mark External Links

NPM version Bundle size GitHub license Travis Build Codecov

Add target and rel attributes to external links.

Automatically detects new links added to the document by installing a mutation observer. This makes it safe to use when adding content via AJAX, using frontend frameworks, etc.

Before

<a href="https://external.web">link</a>

After

<a href="https://external.web" target="_blank" rel="nofollow noopener noreferrer">link</a>

Installation

npm install mark-external-links

Usage

Import and call markExternalLinks().

import markExternalLinks from 'mark-external-links'
 
markExternalLinks()

Options

All options and their defaults:

markExternalLinks({
  target: '_blank',
  rel: 'nofollow noopener noreferrer',
  test: link => link.hostname !== window.location.hostname
})

In the browser

If you don't have the luxury of using a bundler, slap it in a script tag and call it a day.

<script src="https://unpkg.com/mark-external-links"></script>
<script>
  markExternalLinks.markExternalLinks()
</script> 

License

MIT

Package Sidebar

Install

npm i mark-external-links

Weekly Downloads

13

Version

1.0.3

License

MIT

Unpacked Size

23.1 kB

Total Files

12

Last publish

Collaborators

  • daun