Find your content:

Search form

You are here

Control the target window of outputfield if a link

 
Share

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?


Attribution to: nickforce

Possible Suggestion/Solution #1

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>

Attribution to: Kyle Thornton

Possible Suggestion/Solution #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>

Attribution to: Sergej Utko
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30253

My Block Status

My Block Content