0

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));
2

Have you tried changing the anchor tag and add target="_blank" rather than the onclick event handler?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.