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
Peter Martensen 8Peter Martensen 8 

Need help with a "Back" button on a VF page

I am trying to make a very simple VF page that shows some text and a "Back" button.  I can't figure out the "Back" button.  Can someone help fix this code?  Thanks!
<apex:page standardController="Opportunity">

  
  <h1>You need to create an Opportunity directly from a Contact.</h1>

<apex:form>
<apex:commandButton value="Cancel" oncomplete="doRedirect();"/>                

            <script type="text/javascript">
                function doRedirect(){
                    window.history.back();
                }

            </script>
</apexform>
</apex:page>
Best Answer chosen by Peter Martensen 8
SarvaniSarvani
Hi Peter,

Everything looks fine except line 15. Change to </apex:form> (Missing Colon). Also when your testing the code how are you testing this. If you directly click on preview button this will open your VF page in brand new window which doesn't have any previous history window and you can't see if  your Cancel button is working.
If you want to test it try pasting the VF page URL  into another existing window and click your Cancel button which will navigate to previous window.

Hope this helps! Please mark as solved if it does

Thanks

All Answers

SarvaniSarvani
Hi Peter,

Everything looks fine except line 15. Change to </apex:form> (Missing Colon). Also when your testing the code how are you testing this. If you directly click on preview button this will open your VF page in brand new window which doesn't have any previous history window and you can't see if  your Cancel button is working.
If you want to test it try pasting the VF page URL  into another existing window and click your Cancel button which will navigate to previous window.

Hope this helps! Please mark as solved if it does

Thanks
This was selected as the best answer
Peter Martensen 8Peter Martensen 8
Thanks!  Stupid colon......