0

How do I make this open in a new tab:

<apex:pageBlockSection >                                                                                  
                 <apex:commandButton value="Amount Spent Over Time" action="https://c.eu6.visual.force.com/apex/AmountSpent2?core.apexpages.request" reRender="newWindow" onComplete="openWindow()"/>
                <apex:commandButton value="Time Since Last Order" action="https://c.eu6.visual.force.com/apex/TimeSinceLastOrder2?core.apexpages.request" reRender="newWindow" onComplete="openWindow()"/>
                <apex:commandButton value="Time Since Last Contact" action="https://c.eu6.visual.force.com/apex/TimeSinceLastContact?core.apexpages.request" reRender="newWindow" onComplete="openWindow()"/>
                <apex:commandButton value="Custom Orders Query" action="https://c.eu6.visual.force.com/apex/CampaignQuery?core.apexpages" reRender="newWindow" onComplete="openWindow()"/>
            </apex:pageBlockSection> 
2
  • I also tried using the window.open JS function and called it using the onClick attribute of the command button, didn't work. <script> function openpage () { window.open(c.cs83.visual.force.com/apex/AmountSpent?core.apexpages.request, '_blank') } </script> <apex:form > <apex:pageBlock title="Select a campaign to setup"> <apex:pageBlockSection > <apex:commandButton value="Amount Spent Over Time" onClick="openPage()"/>
    – MGS
    Oct 18 '16 at 21:24
  • What happens when you click the button? Any console errors?
    – sfdcfox
    Oct 18 '16 at 23:00
2

You can try with a CommandLink as:

<apex:commandLink target="_blank" styleClass="btn" style="text-decoration:none;padding:4px;" 
action="https://c.eu6.visual.force.com/apex/AmountSpent2?core.apexpages.request" value="Amount Spent Over Time"/>
1
  • You have sufficient reputation to add such one liners as comment.Try to be more descriptive when providing answers.
    – Mr.Frodo
    Oct 19 '16 at 7:07
0

Use window.open and give target blank.

<script>
    function openpage () {
       window.open(URL, '_blank');
    }
    </script>
2
  • Nothing, @shravanboddula
    – MGS
    Oct 19 '16 at 5:04
  • @MGS This is just the javascript. You have to write the button with onclick as the above function.
    – MnZ
    Apr 17 '17 at 4:17
0

Create New Contact (Salesforce style button target _blank)

<apex:commandLink target="_blank" styleClass="btn" style="text-decoration:none;padding:4px;" action="{!URLFOR($Action.Contact.NewContact)}" value="Create New Contact" />
0

Using apex:commandLink changes your styling due the the syntax of an anchor, text inside an anchor is annoying to deal with especially when the anchor is a btn. Additional CSS is then required.

I used this approach with an onclick, removed the action, added a rerender="none".

This works for me:

<apex:commandButton id="GoogleMaps" styleclass="btn btn-success font-weight-bold" style="height:60px;" value="NAVIGATE" rerender="none"
    onclick="window.open('https://www.google.com/maps/dir/?api=1&destination={!Case.Location__c}+&travelmode=driving','_blank');">
</apex:commandButton>

Allowed me to keep consistient styling with all other buttons.

All that said it sounds like this didn't work previously so maybe Salesforce will regress it in the future????

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.