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>
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]);}
you mean you don’t want to change the links in frames?
if so, you need to add
to your script
EDIT
ok. from your comment
i believe this is what you’re looking for:
source: How to replace plain URLs with links?