-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
OSOE-576: Fixing target-blank.js
- Loading branch information
Showing
4 changed files
with
10 additions
and
1,322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
(function initTargetBlank() { | ||
function targetBlank() { | ||
function addTargetBlank() { | ||
const links = document.querySelectorAll('a'); | ||
const currentHostname = window.location.hostname; | ||
|
||
for (let i = 0; i < links.length; i++) { | ||
if (!links[i].href.match(/^mailto:/) && | ||
(links[i].hostname !== currentHostname && | ||
(!links[i].href.match(/^javascript:/i)))) { | ||
if (links[i].hostname !== currentHostname && | ||
// The no-script-url rule triggers to prevent the usage of javascript: URLs. | ||
// In the current script, we are not using them. | ||
// eslint-disable-next-line no-script-url | ||
!links[i].href.startsWith('javascript:') && | ||
!links[i].href.startsWith('mailto:')) { | ||
links[i].setAttribute('target', '_blank'); | ||
} | ||
} | ||
} | ||
window.addEventListener( | ||
'load', | ||
() => { | ||
window.setTimeout(targetBlank, 100); | ||
}, | ||
false); | ||
document.addEventListener('DOMContentLoaded', addTargetBlank); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.