我正在使用下面的javascript代码将我的内容数据(http,https)替换为带有class="disableUrl“rel="nofollow”的锚标签
我的代码是
content.replace(/\n/g,"<br>")
#URLs starting with http://, https://, or ftp://
replacePattern = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim
replacedText = content.replace(replacePattern, "<a class='disableUrl' rel='nofollow'>$1</a>")我的示例内容是
This is the about google http://www.google.com sample. This sample data has images too
<img src="https://assets/mkmmmm"/>在上面的内容中,http://www.google.com被转换为
<a href="http://www.google.com" class="disableUrl" rel="nofollow">http://www.google.com</a> 此外,它还在图像标记的src中为https生成锚标记。喜欢
使用<img src="<a class='disableUrl' rel='nofollow'>https://assets/mmm</a>" />的<img src="https://assets/mmm/>我怎么才能避免这种情况..
发布于 2012-08-28 19:51:37
您标记了jQuery,因此:
$('a').addClass('disableUrl').attr('rel', 'nofollow');https://stackoverflow.com/questions/12157006
复制相似问题