If you have a relatively recent 2.6 or later build of Sideview Utils, there is actually a hidden view demonstrating this exact thing.
navigate manually to:
/en-US/app/sideview_utils/testcases_for_link_rewrite_custom_behavior
The page will talk about how it works a little bit. It basically puts a CustomBehavior module into the page,
<module name="CustomBehavior">
<param name="customBehavior">addSelectionToAllLinksOnPage</param>
</module>
You put this at a point downstream from all the changes you want to preserve, and then it uses a little custom code which is packaged in application.js, and which looks like:
UPDATE - the code posted earlier was incomplete and I've updated it.
if (typeof(Sideview)!="undefined") {
/*
* advanced customBehavior and other custom code to implement a feature
* whereby several views can have one or more pulldowns, where even if
* the user navigates away from the view to another random view, if the
* pulldown(s) are present in the new view, the selected value is always
* passed from the first view to the second. Again, this behavior happens
* even if the user uses the app navigation bar to switch views.
* As such the implementation involves actively rewriting the href
* attributes of the actual link elements in the HTML.
*/
var fieldsToPreserve = ["test1", "host"];
function rewriteLinks(argDict) {
// We start by getting a collection of all the link elements within the
// AppBar module (aka the app navigation menus).
var linksToRewrite = $("div.AppBar a");
// depending on version the submenus of the AppBar may not actually be
// in the AppBar module's container div.
var splunkVersion = Splunk.util.getConfigValue("VERSION_LABEL");
if (Sideview.utils.compareVersions(splunkVersion,"4.3") > -1) {
var extraMenuLinks = $("body .outerMenuWrapper .innerMenuWrapper a");
linksToRewrite = linksToRewrite.add(extraMenuLinks);
}
linksToRewrite.each(function(i) {
var a = $(this);
var href = a.attr("href");
// dont mess with these links. They might have their own args.
if (a.text() == "Help" || a.text() == "About" || href.charAt(0)=="#") return true;
// dont mess with these links either. Especially with the patch to
// get all the links that 4.3 puts at the bottom of the page, we're
// going to be iterating through links that are from a number of
// other modules that have action menus.
if (href.substring(0,11)=="javascript:") return true;
// nor do we touch links that go to other apps.
if (href.indexOf("/app/" + Splunk.util.getCurrentApp() + "/")==-1) return true;
var newArgDict = {};
if (href.indexOf("?")!=-1) {
// make sure to preserve any existing args (uncommon but important).
var existingArgDict = Sideview.utils.stringToDict(a.attr("href").substring(href.indexOf("?")+1));
// well not all of them. We're about to write new definitive
// values for our "fieldsToPreserve" ones, so we throw the
// old values away.
for (var i=0,len=fieldsToPreserve.length;i<len;i++) {
delete existingArgDict[fieldsToPreserve[i]];
}
$.extend(argDict,existingArgDict);
// clean all the old qs args off the string.
href = href.substring(0,href.indexOf("?"));
}
href += "?"+Sideview.utils.dictToString(argDict);
$(this).attr("href",href);
});
};
Sideview.utils.declareCustomBehavior("addSelectionToAllLinksOnPage", function(customBehaviorModule) {
customBehaviorModule.onContextChange = function() {
var context = this.getContext();
var args ={};
for (var i=0,len=fieldsToPreserve.length;i<len;i++) {
var f = fieldsToPreserve[i];
// get the untemplated value if there is one.
var value = context.get(f + ".rawValue") || context.get(f);
if (value) {
args[f] = value;
}
}
// an option you might also need is to preserve the current
// timerange as seen from the customBehavior module.
//var range = context.get("search").getTimeRange();
//if (range.getEarliestTimeTerms()) args["earliest"] = range.getEarliestTimeTerms();
//if (range.getLatestTimeTerms()) args["latest"] = range.getLatestTimeTerms();
rewriteLinks(args);
}.bind(customBehaviorModule);
});
// this rewrites the page links initially, so that they're set before even
// the first context push hits our CustomBehavior. We have to wait until
// allModulesInHierarchy is fired or else the AppBar's menus wont exist.
$(document).bind("allModulesInHierarchy", function() {
var qsDict = Sideview.utils.stringToDict(document.location.search.substring(1));
rewriteLinks(qsDict);
});
}
Unfortunately in 6.0 they changed the app navigation menu entirely so this customBehavior will only work on 5.0 and earlier. It shouldn't be too hard to update for 6.0 if you need to.
... View more