Develop an unobtrusive approach - if a form has the data-warn-unsaved="true" attribute then attach change event handlers to its fields. Do this for all such forms on the page. The handlers can set data-unsaved-changes="true" on the form.
Set window.onbeforeunload to a function that checks for any forms with data-unsaved-changes="true". If any such forms are found, return some text to be displayed as a prompt to the user.
When a form's contents are saved successfully, we want to set data-unsaved-changes="false". Define an event that can be invoked upon a successful save, in order to set the attribute's value?
Also see http://codethug.com/2013/02/01/knockout-binding-for-onbeforeunload/