Use this script
<script>
function convertlink(text) {
var urlRegex = /(https?:\/\/[^\s]+)/g;
return text.replace(urlRegex, function(url) {
return '<a href="' + url + '">' + geturl(url) + '</a>';
})
}
function geturl(url){
if(url.length > 20){
return url.substr(0,20) + "...";
} else {
return url;
}
}
var str = "The Northrop Grumman X-47B https://en.wikipedia.org/wiki/Northrop_Grumman_X-47B is a demonstration unmanned combat air vehicle (UCAV) designed for carrier-based operations."
alert(convertlink(str));
</script>