Created
December 6, 2012 08:48
-
-
Save nashingofteeth/4222924 to your computer and use it in GitHub Desktop.
change plain txt url into html link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="test"> | |
http://google.com | |
</div> | |
<script> | |
var txt = document.querySelector('body').innerHTML; | |
var pattern = /(HTTP:\/\/|HTTPS:\/\/)([a-zA-Z0-9.\/&?_=!*,\(\)+-]+)/i; | |
var replace = "<a href=\"$1$2\">$1$2</a>"; | |
var result = txt.replace(pattern , replace); | |
document.querySelector('body').innerHTML = result; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment