url형식에 자동링크 가능한가요?
본문
답변 1
<script>
function autolink(id) {
var container = document.getElementById(id);
var doc = container.innerHTML;
var regURL = new RegExp("(http|https|ftp|telnet|news|irc)://([-/.a-zA-Z0-9_~#%$?&=:200-377()]+)","gi");
var regEmail = new RegExp("([xA1-xFEa-z0-9_-]+@[xA1-xFEa-z0-9-]+\.[a-z0-9-]+)","gi");
container.innerHTML = doc.replace(regURL,"<a href='$1://$2' target='_blank'>$1://$2</a>").replace(regEmail,"<a href='mailto:$1'>$1</a>");
}
</script>
<div id="test">
http://maniacamp.com/examples/validate_howto.html
</div>
<script>autolink('test');</script>
답변을 작성하시기 전에 로그인 해주세요.