0

I have this commandLink in my visualforce page

<apex:commandLink value="{!Order.Name}" onclick="window.top.location='/{!Order.id}';"/>

When I simply left click the link it redirects just fine.

However, when I right click and click "open link in new tab" I get this error in the new window. [URl No longer exists error How do I allow the link to be opened in a new tab?

2 Answers 2

1

You can try putting target="_blank" property in apex:commandLink.

<apex:commandLink value="{!Order.Name}" target="_blank" 
    onclick="window.top.location='/{!Order.id}';"/>

You can also try using URLFOR to protect from implementation detail.

 <apex:commandLink action="{!URLFOR($Action.Order.View, o.Id)}" 
 value="{!o.Name}" target="_blank" />
3
  • target="_blank" forces the link to open in a new tab. I want the link on left click to be in the current tab, and when you right click>"open in new tab" it opens in a new tab.
    – bogus
    Jun 27, 2019 at 14:32
  • you can use target="_self" which will open in current tab. Jun 27, 2019 at 15:00
  • Yeah it does doesn't it. But it still throws and error when you right click> open in new tab
    – bogus
    Jun 27, 2019 at 15:06
0

I found a fix, you gotta use a outputLink instead of a commandLink

For the commandLink:

<apex:commandLink value="{!Order.Name}" onclick="window.top.location='/{!Order.id}';"/>

I used this outputLink:

<apex:outputLink onclick="window.top.location=('/{!o.id}');" value="/{!o.Id}">{!o.Name}</apex:outputLink>

The reason I have onclick is because my VF page is imbedded in a page layout and I want to completely redirect to a new page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .