Add target=blank to links in formatted text via js
This commit is contained in:
parent
d90f1b86b8
commit
812c192910
5 changed files with 18 additions and 28 deletions
|
|
@ -0,0 +1,12 @@
|
|||
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"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue