Are there any known workarounds for controlling the target window when clicking a link if the link was generated from an outputfield?

I didn't see anything mentioned in the docs on this.. but it would be nice so I don't have to perform extra queries to display the name of an OwnerId for example.



<apex:outputLink value="/{!t.OwnerId}" target="_parent">{!ownerNameString}</apex:outputLink>

Is it possible to specify a target attribute like in the outputLink above, but instead for an outputField when it will be rendered as a link?

  • Could you please elaborate more here ?Can you post some code you have used – Mohith Shrivastava Mar 17 '14 at 8:40
  • @MohithKumar added an example – nickforce Mar 17 '14 at 9:03

I don't think it is possible with a standard visualforce.
One workaround is to catch the click event on all a tags that are wrapped with an element with a certain css class and "redirect" the link target to the new window/tab. For example:

    jQuery(document).ready(function() {
        jQuery('.openInPopup a').click(function(event) {

<apex:outputPanel layout="block" styleClass="openInPopup">
    <apex:pageBlock mode="edit">
            <apex:outputField value="{!a.CreatedById}"/>
| improve this answer | |

An easier solution that doesn't involve jQuery is to get the field and just add the target attribute to it. Something along the lines of:

<apex:inputField value="{t.owner}" id="ownerId"/>

  document.getElementById('{!$Component.ownerId}').target = "_blank";
| improve this answer | |

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.