How can I make the highcharts credits url
to open in new tab?
credits: {
enabled: true,
text: 'text',
href: 'url'
},
You could redefine the credits click handler after the plot is drawn in the charts load event:
chart: {
events:{
load: function() {
this.credits.element.onclick = function() {
window.open(
'http://www.example.com',
'_blank'
);
}
}
}
},
Fiddle here.
Here is solution that worked for me.
credits: {
enabled: true,
text: 'text',
href: 'javascript:window.open("http://www.example.com/", "_blank")'
},
http://jsfiddle.net/ptasdfmk/
// Plugin to add support for credits.target in Highcharts.
Highcharts.wrap(Highcharts.Chart.prototype, 'showCredits', function (proceed, credits) {
proceed.call(this, credits);
if (credits.enabled && this.credits) {
this.credits.element.onclick = function () {
// dynamically create an anchor element and click it
// use the settings defined in highcharts (credits.target)
var link = document.createElement('a');
link.href = credits.href;
link.target = credits.target;
link.click();
}
}
});
$('#container').highcharts({
credits: {
enabled: true,
text: 'CREDITS',
href: 'http://example.com',
target: '_blank'
},
});
Using the Highcharts configuration (credits section with target) a new link element is created on the fly and clicked, when you click "CREDITS". Chained events. This allows to reuse the code and act based on the configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With