I have the following link:
x = <a href="https://t.co/LwlI7i81">https://t.co/LwlI7i81</a>
how can I use javascript to modify the url, to add a target _blank?
String.prototype.parseURL = function() {
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) {
console.log(url.link(url))
return url.link(url);
});
};
If you can extract the element from the DOM that you want (i.e. the link itself) then you can simply call
myLink.setAttribute('target', '_blank');Note that this will not work with the raw HTML assigned to a variable as a string.