Dashboards & Visualizations

Simple XML: How to call a JavaScript function from the HTML panel?

helge
Builder

I would like to call a JavaScript function defined in application.js when the user clicks a link in a Simple XML dashboard. I have the following code:

<html>
   <p>Click on a row in the table to get more information.</p>

   <p><a href="javascript:void(0);" onClick="toggleHidden('Explanation');">Explanation of the data in the table</a></p>

This does not work because the parameters of the a tag are stripped. Using Chrome Developer Tools I see that it looks like this when the page has been loaded:

<html>
   <p>Click on a row in the table to get more information.</p>

   <p><a href="">Explanation of the data in the table</a>

The same code works perfectly when included like this:

<html src="process_detail_explanation.html">
</html>

Is this a bug or by design? I could not find it documented anywhere.

alacercogitatus
SplunkTrust
SplunkTrust

This is by design to prevent XSS attacks, and other malicious intents. BUT - there is a way to do this!

Note : In Splunk 6.X application.js is not loaded automatically. Instead, use dashboard.js.

require(['jquery'],
function($){
    $('#explanation_control').click(function() {
            $("#Explanation").slideToggle( { direction: 'down'}, 500);
    });
}
 );

And you need to update your a to this:

<a href="#" id="explanation_control">Explanation of the data in the table</a>

alacercogitatus
SplunkTrust
SplunkTrust

Did this help you? Please accept the answer if so.

0 Karma

aljohnson_splun
Splunk Employee
Splunk Employee

Why not add the listener to application.js?

0 Karma

JoshWhaley
Path Finder

Did you ever find a solution to this? I'm having the same issue.

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...