a11yist/app/javascript/controllers/rich_text_link_targets_controller.js
david 812c192910
Some checks failed
/ Run tests (push) Failing after 15s
/ Run system tests (push) Failing after 14s
/ Build, push and deploy image (push) Has been skipped
Add target=blank to links in formatted text via js
2024-10-26 20:57:41 +02:00

12 lines
342 B
JavaScript

import { Controller } from "@hotwired/stimulus"
// Connects to data-controller="rich-text-link-targets"
export default class extends Controller {
connect() {
this.element.querySelectorAll('div.trix-content a').forEach(function(link) {
if (link.host !== window.location.host) {
link.target = "_blank"
}
})
}
}