Add link target based on target page document type
In my XSLT I build a sub menu with a list of hyperlinks. I'd like to add some additional code. I recently created a document type for PDF documents that is a content node wrapper around a media item. Those items now show up in my sub menu. When a user clicks them, I want them to open in a new window or new tab. If I try and do that in the wrapper template, modern browsers such as Chrome block the action. A popup is blocked if not initiated by the user such as via a click. So, I need to open the new tab with the click, which then redirects to the PDF.
Here is my current snippet for a typical list item:
It's been a while since I did XSLT myself unfortunately.
However I think you should be able to do something like the following
<li>
<a href="{umbraco.library:Replace(umbraco.library:NiceUrl(@id),'www.azbar.stg',umbraco.library:RequestServerVariables('SERVER_NAME'))}">
<!-- If the niceUrl contains .pdf then add the target attribute to the link with a value of _blank to open it in a new window-->
<xsl:if test="contains(umbraco.library:NiceUrl(@id),'.pdf')">
<xsl:attribute name="target">
<xsl:text>_blank</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="@nodeName"/>
</a>
</li>
Instad of using contains you can also consider using the substring method perhaps.
Add link target based on target page document type
In my XSLT I build a sub menu with a list of hyperlinks. I'd like to add some additional code. I recently created a document type for PDF documents that is a content node wrapper around a media item. Those items now show up in my sub menu. When a user clicks them, I want them to open in a new window or new tab. If I try and do that in the wrapper template, modern browsers such as Chrome block the action. A popup is blocked if not initiated by the user such as via a click. So, I need to open the new tab with the click, which then redirects to the PDF.
Here is my current snippet for a typical list item:
How can I reference the document type and conditionally add a target to my anchor tag?
Hi Connie
It's been a while since I did XSLT myself unfortunately.
However I think you should be able to do something like the following
Instad of using contains you can also consider using the substring method perhaps.
Does this work?
/Jan
is working on a reply...