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?


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?

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.
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

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

note the

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:

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


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