I’m trying to use a mailto-link, I’ve already “hacked” the script to omit the target parameter if it’s an email address but unfortunatly it converts the @ to the decimal @
Screenshot from browser:
The link gets transferred via string flow variable.
The code in question:
names = $${Sname_linkList}$$.split(/\r?\n/)
urls = $${Surls_linkList}$$.split(/\r?\n/)
var containerDiv = document.createElement(‘div’);
containerDiv.id = ‘link-list’;
names.forEach((name, index) => {
var linkItem = document.createElement(‘div’);
linkItem.style.display = ‘flex’;
linkItem.style.alignItems = ‘center’;
linkItem.style.marginBottom = ‘10px’;
var link = document.createElement('a');
link.href = urls[index];
if (urls.some(url => url.includes("mailto"))){
}
else {
link.target = "_blank";
}
The flow variables, the @ in the link text works fine.
The problem with KNIME is that it changes characters like the @ symbol into HTML entities, which are things like @, when you put flow variables into the JavaScript view.
To fix this issue quickly you can change the @ symbol back to what it’s supposed to be after you read the variable. You can do this with the following JavaScript code:
If you think you will have other special characters too then you can use the browser to change everything back, to normal.
You can use this JavaScript function to do that:
function decodeHtml(html) {
var txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;
}
var urls = decodeHtml($${Surls_linkList}$$).split(/\r?\n/);
Also, your mailto: handling is correct skipping target="_blank" for email links is the right call, as it prevents a blank tab from opening alongside the email client.