Trapping navigation away

When a user is filling in a form and inadvertently clicks on a link to another page, or clicks the back button, it sends the browser to a new page and discards all user input. In the event that the form is large and complex, this can represent a significant lost effort.

In this recipe, we will create a Visualforce page that allows a user to create a contact record. If the user clicks on a button to save the record or cancel the creation, they will be requested to confirm that they wish to continue with the action. If the user clicks on the Save or Cancel button, this will submit the form without further confirmation.

Getting ready

This recipe uses the jQuery (http://jquery.com/) JavaScript framework to swap the buttons. The ...

Get Visualforce Development Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.