Opening Link in New Tab Search Item Display Template Sharepoint Online
-
21-12-2020 - |
Pregunta
I followed this article to create a display item template for search. I want to open the title field in a new tab, right now when you click on the link from the search results, it opens in the same page. I have used a function on the onclick event of the href tag. But the link open on the same page and the function 'openInNewTab' is not getting called. Any Suggestions?
<script>
function openInNewTab(url) {
alert("openInNewTab function called");
var win = window.open(url, '_blank');
win.focus();
}
</script>
var titleHtml = String.format('<a clicktype="{0}" onclick="openInNewTab(url); return false;" id="{1}" href="{2}" class="ms-srch-item-link custom-item-link" title="{3}" onfocus="{4}" {5}>{6}</a>',$htmlEncode(clickType), $htmlEncode(id + Srch.U.Ids.titleLink), $urlHtmlEncodeString(url),$htmlEncode(ctx.CurrentItem.Title),
showHoverPanelCallback, appAttribs, Srch.U.trimTitle(title, maxTitleLengthInChars, termsToUse));
Solución
Have you tried changing the anchor tag and add target="_blank"
rather than the onclick event handler?
Licenciado bajo: CC-BY-SA con atribución
No afiliado a sharepoint.stackexchange