私のページのすべてのURLにハイパーリンクを作成しようとしています。 は、このようなコードがあります:Html URL上にハイパーリンクを作成します。img src以外のリンクはありません。
<div id="divC">
Hello testing message
My profile link : http://stackoverflow.com/users/568085/abhishek and
my user account link :
<a href="http://stackoverflow.com/users/568085/abhishek">
<img height="58" width="208" title="Stack Overflow profile for Abhishek at Stack Overflow, Q&A for professional and enthusiast programmers" alt="Stack Overflow profile for Abhishek at Stack Overflow, Q&A for professional and enthusiast programmers" src="http://stackoverflow.com/users/flair/568085.png?theme=dark">
</a>
</div>
と私はコンテンツページ内のすべてのURLにリンクを追加するにはjavascript関数の下に使用:上記のコードで
<script>
//call function for linking every url
createLinks();
function createLinks()
{
var exp=/(((\b(https?|ftp|file):\/\/))[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
$("div#divC").each(function(index) {
$(this).html($(this).html().replace(exp, "<a target='_self' class='msg_links' href=$1>$1</a>"));
});
}
</script>
は細かい作業が、私は作成しません<img src='www.test.com'>
のリンク。 私はこれを実行すると、それはまた<img src="<a href='www.test.com'>www.test.com</a>" >
にリンクを作成し、私は<img>
SRCにリンクを作成避けることができますどのように
。?
これを行うには正規表現を調整する必要があります。 – Malk