1

I wonder if there is a JavaScript that automatically turns text into a link when you type in “www.example.com”?

HTML

<div id="test">
If I type in www.example.com I want it to become a link automatically.
</div>

Javascript:

$(window).load(function(){
document.getElementById('test').contentEditable = true;
// how 
});
Hakan
  • 3,835
  • 14
  • 45
  • 66

1 Answers1

1

Check out this answer for how to replace text urls with links, but what I'd probably do is set an onblur event handler on the element, and in that, replace the text with the result of replaceURLWithHTMLLinks().

Community
  • 1
  • 1
lakenen
  • 3,436
  • 5
  • 27
  • 39