I have a project at work where we’re looking to present a user with an edit message if they’ve changed anything within a web page and haven’t saved the form before closing the page to stop them from losing changes. The following example works with IE 6 (which is our corporate browser). It does not seem to work with firefox, and I haven’t checked with any other browser since our need is isolated to IE.
<html>
<body>
<script type=”text/javascript”>
document.write(“Hello World!”);
var needToConfirm = false;
//Call this function if some changes is made to the web page and requires an alert
//you could call this is Keypress event of a text box or so…
function setDirtyFlag()
{
needToConfirm = true;
}//this could be called when save button is clicked
function releaseDirtyFlag()
{
needToConfirm = false; //Call this function if dosent requires an alert.
}
window.onbeforeunload = confirmExit;
function confirmExit()
{
if (needToConfirm)
return “You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?”;
}
</script>
</body>
</html>
I’ve been exploring for a little for any high quality articles or blog posts on this sort of area . Exploring in Yahoo I at last stumbled upon this site. Reading this info So i am happy to express that I’ve a very just right uncanny feeling I discovered exactly what I needed.
I most without a doubt will make certain to do not omit this site and give it a glance on a constant
basis.
That is a good tip particularly to those fresh to
the blogosphere. Short but very accurate information… Appreciate
your sharing this one. A must read post!
Hey would you mind stating which blog platform you’re using? I’m planning to start
my own blog soon but I’m having a difficult time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m
looking for something unique. P.S Apologies for getting off-topic but I had to ask!
It’s WordPress. I set it up quite a long time ago. They have template themes you can use. Petty easy to use. And free.
Sent from my iPad.