我想給rel="nofollow"
發送我的外部鏈接,其內容由ckeditor管理。如何將rel =「nofollow」添加到CKEditor中的鏈接(如果它是外部鏈接的)
example.com =我的網站
externallink.com =任何外部鏈路
例如:
<p>
Lorem <a href="https://example.com/an-article.html">ipsum</a> dolar
<a href="http://externallink.com/example.html" rel="nofollow">sit</a> amet.
</p>
將該溶液:
editor.dataProcessor.htmlFilter.addRules(
{
elements :
{
a : function(element)
{
if (!element.attributes.rel)
element.attributes.rel = 'nofollow';
}
}
});
從https://stackoverflow.com/a/6930940/1848929將nofollow
添加到全部a
元素。
如何只過濾外部鏈接?
約CKEditor的數據處理器還深DOC:http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Data_Processor
注:使用這些問題的答案#2的文本編輯器。在這個問題中檢查兩個鏈接的rel屬性。
我在我的頁面上使用cdn上的<script src="//cdn.ckeditor.com/4.5.10/standard/ckeditor.js"></script>
。
但我的管理面板位於一個子域。如https://panel.example.com,您的解決方案是否涉及https://example.com? – hakiko
而不僅僅是硬編碼你想要的主機而不是location.host – epascarello
element.host在控制檯日誌 – hakiko