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
Jina ChetiaJina Chetia 

How to add Back Button functionality in a VisulaForce page?

Hi,

I want add "Back' button functionality on my pages and the same pages are rendered from lot of places. As javascript:history.back() 
does not work in ViaualForce, is there any other way to acjieve this?

Thanks
Jina
ESES
You want to go back to the page you came from? I guess you can add a paremeter like "retURL" and then have an action method that takes you back to what ever is the value for this parameter and to some default page if retURL hasn't been specified.
lnryanlnryan
Just to add some more detail if it helps.

If you've set the retURL in your source link, assigning either the {!save} and {!cancel} methods to an apex commandButton will take you to whatever you've set. For instance in our case we had the following button in a list view

Code:
<apex:facet name="caption" >
    <script>
        function gotonew(){
            window.location.href = '/apex/xRDOpportunityProduct?mode=new&Opportunity={!Opportunity.id}&retURL=/apex/xRLOpportunityProducts?id={!Opportunity.id}';
        }
    </script>
    <input id="newbtn" type='button' class='btn' value="New Product" onClick="javascript&colon;gotonew()"/>
</apex:facet>

 
note the
&retURL=/apex/xRLOpportunityProducts?id={!Opportunity.id}

at the tail-end of the javascript redirect with the source page record id included.

on the source page we found directly creating a standard HTML button easier than figuring out the apex tag version, but we made it look the same by using the 'btn' class.

on the target page, we relied directly on apex elements and needed no additional javascript.
here are our save and cancel buttons, sweet and easy:

Code:
<apex:column>
     <apex:commandButton action="{!save}" value="Save Changes" styleClass="btn" />
     <apex:commandButton action="{!cancel}" value="Cancel" styleClass="btn" />
</apex:column>

 






Message Edited by lnryan on 06-14-2008 02:57 PM