Created
September 11, 2017 00:12
-
-
Save ifo/aee7665bae5ab1f77e891d1ca5b87b93 to your computer and use it in GitHub Desktop.
Safely force RC Scout links to open in a new tab on click.
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
// Wrap this in a <script></script> tag | |
// and paste it directly below your RC scout script tag. | |
;(function() { | |
'use strict'; | |
// Don't do anything if rcs isn't loaded. | |
if (!window._rcs) { return } | |
// Get the a tag class name. | |
var className = window._rcs.inst.prefix + "__link"; | |
// Get all the a tag links. | |
var links = document.getElementsByClassName(className); | |
// Add the target and rel attributes. | |
for (var i = 0; i < links.length; i++) { | |
var link = links[i]; | |
link.setAttribute('target', '_blank'); | |
link.setAttribute('rel', 'noopener noreferrer'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment