Dashboards & Visualizations

AppBar links Open in New Window

Ant1D
Motivator

Hey,

How can I configure some of my Appbar Links (e.g Search, Summary links from the Search app) so that when a user clicks on them, these links open up a view in a new window.

I want some of my main menu links to have the behaviour of a viewRedirector link that has popup set to True.

Is this possible in Splunk?

Thanks in advance for your help.

1 Solution

sideview
SplunkTrust
SplunkTrust

Note: this has been updated since the original post. The AppBar module will let <a> tags through but for some reason it strips out target attributes and onclick attributes we we put a little workaround into `etc/apps//appserver/static/application.js


There's a strange loophole in the AppBar module that you can exploit to do this.

The loophole is that the code never screens what that XML actually is, it just goes in there and looks for <collection> nodes and <view> nodes and replaces them with other stuff.

So the upshot is that if you just put some random well-formed HTML into default.xml, it will generally survive the perilous journey to the UI, and your <b>Hello World</b> will emerge quite happily embedded into the nav.

That said, it curiously strips some attributes out. so if you do an anchor tag with an href attribute, the href will survive, but if you put a target attribute in there it will not.

So the solution then has two parts: Part 1 is to put this into the default.xml file

...
<view name="normal_view_link" />
<a href="custom_view#newWindow">Custom Link Label</a>
...

and part 2 is to add this javascript to your application.js file, at etc/apps/<appname>/appserver/static/application.js. If the file doesnt exist already just create it.

$(document).ready(function() {
    $(".AppBar a").each(function(i, link) {
        var href = $(link).attr("href");
        if (href.indexOf("#newWindow") > 0) {
            $(link).attr("target","_blank");
            href = href.substring(0,href.indexOf("#newWindow"));
            $(link).attr("href",href);
        }
    });
})

UPDATE: the original answer was a lot simpler, but indeed the target attributes get mysteriously killed along the way so we had to use some JS to build them for us.

View solution in original post

vikky
New Member

Hi we have done the small change in admin.js function and its working fine for us.

$(document).ready(function() {
$(".AppBar a").each(function(i, link) {
var href = $(link).attr("href");
if (href.indexOf("#newwindow") > 0) {
$(link).click(function(e){

$(link).attr("target","_blank");
href = href.substring(0,href.indexOf("#newwindow"));
$(link).attr("href",href);

        });
    }
});

})

and used the below in default.xml (navigation)

<a href="http://google.co.in#newWindow" target="_blank">Click Here</a>

0 Karma

vikas_gopal
Builder

Hi Vikky,
As you said you achieved it can you please let me know how did you call your admin.js in the default.xml file.
I followed all the steps but it seems my js file is getting ignored by default xml.
Please help

0 Karma

sideview
SplunkTrust
SplunkTrust

Note: this has been updated since the original post. The AppBar module will let <a> tags through but for some reason it strips out target attributes and onclick attributes we we put a little workaround into `etc/apps//appserver/static/application.js


There's a strange loophole in the AppBar module that you can exploit to do this.

The loophole is that the code never screens what that XML actually is, it just goes in there and looks for <collection> nodes and <view> nodes and replaces them with other stuff.

So the upshot is that if you just put some random well-formed HTML into default.xml, it will generally survive the perilous journey to the UI, and your <b>Hello World</b> will emerge quite happily embedded into the nav.

That said, it curiously strips some attributes out. so if you do an anchor tag with an href attribute, the href will survive, but if you put a target attribute in there it will not.

So the solution then has two parts: Part 1 is to put this into the default.xml file

...
<view name="normal_view_link" />
<a href="custom_view#newWindow">Custom Link Label</a>
...

and part 2 is to add this javascript to your application.js file, at etc/apps/<appname>/appserver/static/application.js. If the file doesnt exist already just create it.

$(document).ready(function() {
    $(".AppBar a").each(function(i, link) {
        var href = $(link).attr("href");
        if (href.indexOf("#newWindow") > 0) {
            $(link).attr("target","_blank");
            href = href.substring(0,href.indexOf("#newWindow"));
            $(link).attr("href",href);
        }
    });
})

UPDATE: the original answer was a lot simpler, but indeed the target attributes get mysteriously killed along the way so we had to use some JS to build them for us.

twkan
Splunk Employee
Splunk Employee

Appreciate Nick's idea, but I am wondering if anyone has this working?

0 Karma

alexiri
Communicator

Probably because Splunk changed the classes for the navbar (at least in 6.2), so the beginning of the javascript should now look like this:

$(document).ready(function() {
    $('.nav-item a').each(function(i, link) {
....
0 Karma

Ant1D
Motivator

Yeah it is mysterious that the target attribute gets ignored. Thanks for the JavaScript. Thanks again for your help.

0 Karma

Ant1D
Motivator

A couple more things...what apps have used it? Could JavaScript be used for this? If so, how?

0 Karma

Ant1D
Motivator

Hey Nick, I have tried this but it doesn't open the link in a new window. It does add custom_view to the AppBar but when you click on the custom_view link, the page just opens in the same window so it appears to be ignoring the target attribute. Any ideas why?

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...