Generic JavaScript View mailto link

Hello

I’m having an issue with the Generic JavaScript View (Workflow Application Header)

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:

image

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.

image

Any help is appreciated :slight_smile:

1 Like

Hi @rkehrli

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:

urls = $${Surls_linkList}$$.split(/\r?\n/).map(u => u.replace(/@/g, '@'));

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.

Hope this helps,

Sena

3 Likes

@NurSenaAlici

Thanks, that worked perfectly. I suspected that it get’s changed along the way.

I should’ve added that I’m on 5.2.4 on the remote AP, on my local 5.11. install it returned the @ just fine.

2 Likes

That’s great! Happy to help :grinning_face_with_smiling_eyes:

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.