function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nickwick76nickwick76 

Why does target work different for different link types in an inline VF-page?

I have created a Visualforce page with a pageblock table and a couple of columns. The first column contains a apex:commandlink element. 
I put this VF-page as an inline VF-element in a page layout. Clicking the link will open the page in the iframe. It doesn't matter what I put in the 'target' attribute (_top, _blank etc.).
If I create a HTML link above the table in the same VF-page the target attribute works, i.e. the new page opens in the whole window or a new window. 

So this code works:
<a href="http://www.salesforce.com" target="_top">test</a>

 

But this does not:
<apex:form >
<apex:outputPanel id="mainOppNotes">
<apex:pageBlock title="Notes" mode="maindetail">
<apex:pageBlockTable value="{!MainOppNotes}" var="n">
<apex:column headerValue="Action" width="5%">
<apex:commandLink action="{!viewNote}" id="viewNote" rerender="mainOppNotes" value="View" styleClass="actionLink" target="_blank">
<apex:param name="noteId" assignTo="{!noteId}" value="{!n.Id}" />
</apex:commandLink>
</apex:column>
<apex:column headerValue="Name" width="65%">{!n.Title}</apex:column> 
<apex:column headerValue="Last Modified" width="30%"><apex:outputtext value="{!n.LastModifiedByName}" />,&nbsp;<apex:outputtext value="{!n.LastModifiedDateStr}" /></apex:column>
</apex:pageBlockTable>
</apex:pageBlock> 
</apex:outputPanel>
</apex:form >
 
Can I affect this in any way? Why does it work like this?
// Niklas
Best Answer chosen by Admin (Salesforce Developers) 
nickwick76nickwick76

Bob,

I tested further with your approach and it works now!

 

I have modified the VF-code to this:

<apex:form >
    <apex:outputPanel id="gotoNote">
	<apex:outputPanel rendered="{!refreshPage}">
<script>
	window.top.location='/{!noteId}';
	</script>
	</apex:outputPanel>
    </apex:outputPanel>
    
    <apex:outputPanel id="mainOppNotes">
<apex:pageBlock title="Notes" mode="maindetail">
		<apex:pageBlockTable value="{!MainOppNotes}" var="n">
		<apex:column headerValue="Action" width="5%">
				<apex:commandLink id="viewNote" rerender="gotoNote" value="View" styleClass="actionLink">
				<apex:param name="refresh" assignTo="{!refreshPage}" value="true" />
					<apex:param name="noteId" assignTo="{!noteId}" value="{!n.Id}" />
				</apex:commandLink>			
			</apex:column>
			<apex:column headerValue="Name" width="65%">{!n.Title}</apex:column> 
		        <apex:column headerValue="Last Modified" width="30%"><apex:outputtext value="{!n.LastModifiedByName}" />,&nbsp;<apex:outputtext value="{!n.LastModifiedDateStr}" /></apex:column>
		</apex:pageBlockTable>
	</apex:pageBlock>	
    </apex:outputPanel>
</apex:form>

 And then added a refreshPage class variable with getter and setter which defaults to false in the constructor and is set to true with the new param tag as you can see above:

public Boolean refreshPage {get; set;}

 Thanks a lot Bob for your help!

 

// Niklas

All Answers

bob_buzzardbob_buzzard

I wrote a blog post on refreshing the containing page from an embedded visualforce page - is this any help:

 

http://bobbuzzard.blogspot.com/2011/05/refreshing-record-detail-from-embedded.html

nickwick76nickwick76

Hi Bob, 

Thanks for your reply and sorry for my late reply.

 

I had to go for another solution since time was not no my side. 

I gave your suggestion a try but it didn't work out for me. Maybe with some more effort it will work out. Thanks anyway!

 

BR / Niklas

@Suresh.ax1214@Suresh.ax1214

Hai

 

you are using the property rerender in command link then vf thinks it is new page.thats why the link is opening in a same page. Replace action with  onClick()="window.open('{!your_method}')". then it will works.

nickwick76nickwick76

Hi Suresh,

I didn't get that to work. 

 

onClick="window.open('{!viewNote}')"

 

gives me the error message "Unknown property 'OpportunityStandardController.viewNote"

 

Your suggestion with parenthesis:

 

onClick()="window.open('{!viewNote}')"

 

gives me the error message "Attribute name 'onClick' associated with an element type "apex:commandLink" must be followed by the '=' character. 

nickwick76nickwick76

Bob,

I tested further with your approach and it works now!

 

I have modified the VF-code to this:

<apex:form >
    <apex:outputPanel id="gotoNote">
	<apex:outputPanel rendered="{!refreshPage}">
<script>
	window.top.location='/{!noteId}';
	</script>
	</apex:outputPanel>
    </apex:outputPanel>
    
    <apex:outputPanel id="mainOppNotes">
<apex:pageBlock title="Notes" mode="maindetail">
		<apex:pageBlockTable value="{!MainOppNotes}" var="n">
		<apex:column headerValue="Action" width="5%">
				<apex:commandLink id="viewNote" rerender="gotoNote" value="View" styleClass="actionLink">
				<apex:param name="refresh" assignTo="{!refreshPage}" value="true" />
					<apex:param name="noteId" assignTo="{!noteId}" value="{!n.Id}" />
				</apex:commandLink>			
			</apex:column>
			<apex:column headerValue="Name" width="65%">{!n.Title}</apex:column> 
		        <apex:column headerValue="Last Modified" width="30%"><apex:outputtext value="{!n.LastModifiedByName}" />,&nbsp;<apex:outputtext value="{!n.LastModifiedDateStr}" /></apex:column>
		</apex:pageBlockTable>
	</apex:pageBlock>	
    </apex:outputPanel>
</apex:form>

 And then added a refreshPage class variable with getter and setter which defaults to false in the constructor and is set to true with the new param tag as you can see above:

public Boolean refreshPage {get; set;}

 Thanks a lot Bob for your help!

 

// Niklas

This was selected as the best answer
@Suresh.ax1214@Suresh.ax1214

hi

Sorry i mistyped the onClick function...
this is correct
onClick="window.open('your method')"
i typed onClick as onClick() thats why it raising the error msg
bob_buzzardbob_buzzard

Glad to see you got there.