Recently, I built a chat. The linkification of content typed into the textarea created some trouble.
if(!String.linkify) {
String.prototype.linkify = function() {
// http://, https://, ftp://
var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim;
// www. sans http:// or https://
var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
// Email addresses
var emailAddressPattern = /[\w.]+@[a-zA-Z_-]+?(?:\.[a-zA-Z]{2,6})+/gim;
return this
.replace(urlPattern, '<a href="$&">$&</a>')
.replace(pseudoUrlPattern, '$1<a href="http://$2">$2</a>')
.replace(emailAddressPattern, '<a href="mailto:$&">$&</a>');
};
}
- Problem: Links in chatlog were not transformed, but appear a pure string.
- Problem: Links contain hidden characters â£https://www.link.com/product/ABC/myaffiliatelink When i called the resulting links, I got the following browser notification:
Not Found The requested URL â£https://www.link.com/product/ABC/myaffiliatelink was not found on this server.
To get the message, I use:
textContainer.textContent = message.linkify();
Can somebody explain what happens and how to fix this?