Have you ever entered information into a WYSIWYG window and then accidently hit the browse back button on your keyboard, your mouse, or in the browser itself before saving the information? It's happen to me many times. In fact, it happened to me as I was writing this post! It's very frustrating to lose your work at the best of times.
WordPress and other CMS' incorporate a feature which displays a warning message before actually leaving a page that has unsaved information. The productivity gain from including such a feature would be great and I would imagine very much appreciated by many people.
The code listed below helps brings us closer to having WebsiteBaker achieving the desired behaviour. While it usually prompts you, in its current version it will do so regardless of whether you made any changes or not. In my case, I would rather be prompted too often and not loose information accidently.
Before you begin making changes, be sure to make a backup of the original modules/wysiwyg/modify.php file before you start making changes to it.
If you are using WebsiteBaker v2.8.1, you can simply replace this file with the attached version. If you are using a different version of websitebaker, you might be better off making the changes manually as follows:
Editing the modules/wysiwyg/modify.php file using a text editor:
STEP 1: Locate the following code around (line 49 in WebsiteBaker v2.8.1):
<form name="wysiwyg<?php echo $section_id; ?>" action="<?php echo WB_URL; ?>/modules/wysiwyg/save.php" method="post">
and replace it with:
<form name="wysiwyg<?php echo $section_id; ?>" action="<?php echo WB_URL; ?>/modules/wysiwyg/save.php" method="post" onclick="needToConfirm=false;">
The only difference is the addition of onclick="needToConfirm=false;". What this does is prevent the warning if the user clicks the Save button.
STEP 2: Right above this line, insert the following code:
<script language="JavaScript">
// Added to confirm leaving the page without saving changes first (even if there aren't any)
var needToConfirm = true;
window.onbeforeunload = confirmExit;
function confirmExit()
{
if (needToConfirm)
return "<?php print($MESSAGE['SETTINGS']['MODE_SWITCH_WARNING']); ?>";
}
</script>
Hopefully this will eventually be integrated permanently into WebsiteBaker with proper language support including using a language variable.
Until then:
- Replace the English text with a translation in your own language (if you want);
- Remember to re-apply this fix whenever you upgrade to a new version of websitebaker.
IMPORTANT: Things you need to know!
- You must have Javascript enabled in order for this to work.
- If there is a Javascript error on the page, the prompt will may not appear.
- There are no guaranties. Test this yourself and decide whether it works for you.
If anyone knows how to detect a change when editing a page, please let me know. This might enable me to only enabling the warnings if a change has actually been made instead of having the message always appear. Any suggestions would be appreciated.
With best regards,
Michael Milette
___________________ ___________________ _______
TNG Consulting Inc.
Providing Sustainable Solutions to Life
www.tngconsulting.c aEdit: I replaced "You have attempted to leave this page. If you have made any changes without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?" with "<?php print($MESSAGE['SETTINGS']['MODE_SWITCH_WARNING']); ?>" in order to provide multilingual support. Also updated attached file.