4

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.

Thanks!

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
2

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:

<script>
    jQuery(document).ready(function() {
        jQuery('.openInPopup a').click(function(event) {
            event.preventDefault();
            window.open(jQuery(this).attr('href'));
        });
    });    
</script>

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

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"/>

<script>
  document.getElementById('{!$Component.ownerId}').target = "_blank";
</script>
| 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.