Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Open external content in new tab #523

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/packs/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ import 'bootstrap'

Rails.start()
ActiveStorage.start()

// Open all external links in a new window
window.addEventListener('click', function (event) {
const target = event.target
const el = target.closest('a')
if (el && !el.isContentEditable && el.host !== window.location.host) {
el.setAttribute('target', '_blank')
el.setAttribute('rel', 'noopener noreferrer')
}
}, true)