html 标题中的 Highcharts img;即使设置了 Highcharts Security AST,onerror 也不会触发

Highcharts img in html title; onerror doesn't fire even with Highcharts Security AST set

如果在 highcharts 标题/文本中找不到图像的 src,我需要 img 的 onerror 函数 运行。

但是,highcharts 不支持开箱即用的 img 错误,我需要将其添加到概述的安全列表中 in the docs

例如

title: {
    useHTML:true,
    text: '<img src="/A/NotFound/src.png" onerror="doSomething(this)" />Solar Employment Growth'
}

我尝试设置 AST 以允许该属性;

Highcharts.AST.allowedAttributes.push('onerror');

但是,在这个fiddle中可以看出,这个函数没有运行。 我错过了什么吗?

该函数未触发,因为元素上没有 src 属性。添加以下代码以允许使用 src 和空字符串引用。

Highcharts.AST.allowedAttributes.push('onerror');
Highcharts.AST.allowedAttributes.push('src');
Highcharts.AST.allowedReferences.push('');

现场演示: https://jsfiddle.net/BlackLabel/aocsn5p4/

文档: https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting