Skip to content

Instantly share code, notes, and snippets.

@ifo
Created September 11, 2017 00:12
Show Gist options
  • Save ifo/aee7665bae5ab1f77e891d1ca5b87b93 to your computer and use it in GitHub Desktop.
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.
// 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