Highcharts中的链接和工具提示中的按钮不起作用。

huangapple go评论84阅读模式
英文:

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: &#39;auto&#39;
	},
	formatter: function(e) {
		return &#39;&lt;div&gt;&#39;+this.x + &#39;: &#39; + this.y +&#39;&lt;br&gt;&lt;a href=&quot;www.google.com&quot;&gt;Click Me&lt;/a&gt;&lt;br&gt;&lt;button onclick=&quot;clicked()&quot; &gt;Hello&lt;/button&gt;&lt;/div&gt;&#39;
	}
}

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(&#39;onclick&#39;);

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

huangapple
  • 本文由 发表于 2023年5月25日 20:06:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76332100.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定