英文:
Highcahrts links and button in tooltip not working
问题
我正在尝试从工具提示内部触发点击事件。我将按钮与点击事件放在其中,但不起作用。我还尝试在工具提示内部放置外部链接,也不起作用。我能够获得元素的样式,但无法触发点击事件。
以下是工具提示配置:
tooltip: {
useHTML: true,
style: {
pointerEvents: 'auto'
},
formatter: function(e) {
return '<div>'+this.x + ': ' + this.y +'<br><a href="www.google.com">Click Me</a><br><button onclick="clicked()">Hello</button></div>';
}
}
我到目前为止尝试过的内容:链接到示例。
英文:
I am trying to trigger a click event from inside the tooltip.
I placed the button with a click event inside it and it is not working.
Also I tried to have an external link inside the tooltip. it is also not working. I am able to get the styling of the elements but not the click event triggered.
here is the tooltip config
tooltip: {
useHTML: true,
style: {
pointerEvents: 'auto'
},
formatter: function(e) {
return '<div>'+this.x + ': ' + this.y +'<br><a href="www.google.com">Click Me</a><br><button onclick="clicked()" >Hello</button></div>'
}
}
Here is something I have tried till now: http://jsfiddle.net/kolliparavamsikrishna/eytroh53/
答案1
得分: 1
因为安全原因,Highcharts默认会过滤通过图表选项结构添加的所有HTML内容。onclick
属性存在潜在风险,因此被过滤掉。
要能够使用onclick
属性,请将其添加到allowedAttributes
表中:
Highcharts.AST.allowedAttributes.push('onclick');
在线演示: http://jsfiddle.net/BlackLabel/om32w81g/
文档: https://www.highcharts.com/docs/chart-concepts/security
API 参考: https://api.highcharts.com/class-reference/Highcharts.AST#.allowedAttributes
英文:
Because of security reasons, Highcharts by default filter all HTML that is added through the chart options structure. The onclick
attribute is potentially risky, so it is filtered out.
To be able to use onclick
attribute, add it to the allowedAttributes
table:
Highcharts.AST.allowedAttributes.push('onclick');
Live demo: http://jsfiddle.net/BlackLabel/om32w81g/
Docs: https://www.highcharts.com/docs/chart-concepts/security
API Reference: https://api.highcharts.com/class-reference/Highcharts.AST#.allowedAttributes
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论