Dashboards & Visualizations

AppBar links Open in New Window

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

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

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

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

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

Splunk Employee
Splunk Employee

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

0 Karma

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

Motivator

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

0 Karma

Motivator

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

0 Karma

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
State of Splunk Careers

Access the Splunk Careers Report to see real data that shows how Splunk mastery increases your value and job satisfaction.

Find out what your skills are worth!