Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Last active July 22, 2017 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/9368cf990d4772ca68275fd344383820 to your computer and use it in GitHub Desktop.
Save walterdavis/9368cf990d4772ca68275fd344383820 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://freewaytalk.softpress.com/lib/prototype.js"></script>
</head>
<body>
<div class="message">
This is some text. Here is a <a href="#">local link</a>.
Here is an <a href="http://www.example.com">external link</a>.
Here is an <a href="http://www.apple.com" rel="foo">external link</a>
that already has a rel attribute.
</div>
<script>
$$('.message a').each(function(elm){
var rel = elm.rel;
if(elm.hostname != window.location.hostname){
elm.rel = [rel, 'nofollow'].reject(
function(r){ return (!!!r || r == 'nofollow'); }
).join(' ');
}
console.log(elm.rel);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment