mark-external-links
v1.0.3
Published
Add target and rel attributes to external links
Downloads
4
Readme
Mark External Links
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>