I'm looking for function code to trigger javascript code upon performing a search on SharePoint list
I have a SharePoint list that i have edited and added a script editor code snippet shown here to force hyperlinks in the list to open in a new tab by adding the #openinnewwindow to the end of the links. This code works great on the list when it loads. However if i perform a search the search result links do not open in a new tab. I believe if i re-trigger the code again this would allow the links to open in new tabs just not sure what to add to trigger.
` _spBodyOnLoadFunctionNames.push("rewriteLinks");
function rewriteLinks() {
//create an array to store all
var anchors = document.getElementsByTagName("a");
//loop through the array
for (var x=0; x<anchors.length; x++) {
//check to see if the current anchor element contain
#openinnewwindow
if (anchors[x].outerHTML.indexOf('#openinnewwindow')>0) {
//add the [target] attribute and rewrite the [href] attribute
anchors[x].target = "_blank";
anchors[x].href = anchors[x].href.replace(/#openinnewwindow/,'');
}
}
}
</script>`