Created
February 2, 2015 23:30
-
-
Save anonymous/5e435053d3e3bfb9281f to your computer and use it in GitHub Desktop.
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 contenteditable>Press enter<br>http://google.com</div> | |
<script> | |
document.onkeydown = function(evt) { | |
evt = evt || window.event; | |
if (evt.keyCode == 13) { // enter key | |
var text = document.querySelector('div').innerHTML; | |
var url = text.match(/(HTTP:\/\/)([a-zA-Z0-9.\/&?_=!*,\(\)+-]+)/i); | |
var foourl = url[0].replace("http", "foo"); | |
document.foo = "foo"; | |
document.http = "http"; | |
var link = text.replace(url[0], "<a href='" + | |
foourl + | |
"' style='cursor:pointer' onclick='var http = this.href.replace(document.foo, document.http); window.open(http);return false'>" + | |
url[2] + | |
"</a>"); | |
document.querySelector('div').innerHTML = link; | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment