i want to replace url with links, the following code work fine but it will harm iframe (e.g. youtube), any advice?thx
$(".css___div p").html($(".css___div p").html().replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,"<a href='$1' target='_blank'>$1</a>"));
update: actually i am doing a bbs, sometime ppl want to post a youtube, so they will make a iframe in the post... for example:
check out my mv!!!
<iframe width="560" height="315" src="http://www.youtube.com/embed/F1C9zIA50Eo" frameborder="0" allowfullscreen></iframe>
http://youtu.be/F1C9zIA50Eo
i want to turn http://youtu.be/F1C9zIA50Eo into a link but not http://www.youtube.com/embed/F1C9zIA50Eo, any hints? thx
update2: finally i did a stupid trick to avoid the code harm iframe:
var var___iframeSRC=$(".css___funk .css___div p iframe").attr("src");
$(".css___div p").html($(".css___div p").html().replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,"<a href='$1' target='_blank'>$1</a>"));
$(".css___funk .css___div p iframe").attr("src",var___iframeSRC);
update3: i put all src to a array... but it still a stupid trick, any advice is welcome
arr___iframeSrc=new Array();
$(".css___funk .css___div p iframe").each(function(){
arr___iframeSrc.push($(this).attr("src"));
});
$(".css___funk .css___div p").html($(".css___funk .css___div p").html().replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,"<a href='$1' target='_blank'>$1</a>"));
for(var i=0;i<arr___iframeSrc.length;i++){$(".css___funk .css___div p iframe").eq(i).attr("src",arr___iframeSrc[i]);}