0

我想rel="nofollow"在我的所有外部链接中添加属性。下面的代码适用于带有http://和的链接https://。我的问题是它不能在没有http(例如:)的链接上工作,/somepage.html我怎么能克服这个。

任何解决方案都受到高度赞赏。

JS小提琴

HTML

<a href="http://www.somepage.com">This is an internal link</a>
<br /><br />
<a href="http://google.com">And this is an external link, with no follow (working)</a>
<br />
<br />
<a href="google.com">And this is an external link, with no follow (not-working)</a>
<br />
<br />
<a href="https://plus.google.com/101147114025225446015/about">And this is an external link, with no follow (working)</a>

JS

jQuery('a[href*="http://"]:not([href*="http://www.somepage.com"])').attr('rel', 'nofollow');

jQuery('a[href*="https://"]:not([href*="http://www.somepage.com"])').attr('rel', 'nofollow');

jQuery('a[href*="https://"]:not([href*="https://www.somepage.com"])').attr("target", "_blank");

JS小提琴

4

0 回答 0