[wikka-community] A "crude" way to protect my wiki users
Michaël Perez
perez.mick
Wed May 21 22:56:06 GMT 2008
Hey guys,
Some of my users have been complaining of accidentally pressing *back* or
clicking on an URL and suddenly realize their unsaved changes to a wiki page
have just disappeared. I understood their frustration, since they are used
to the "user friendliness" of say MS Word. If GMail could do it, I could do
it as wel...
So here is my javascript solution, you add underneath snippet to header.php
just before </HEAD>
<SCRIPT LANGUAGE="JavaScript">
function AlertOnExit()
{
var temp = new String(window.location.href);
var temp2 = new String('/edit?id=');
if (temp.indexOf(temp2) >= 0)
{
event.returnValue = "You have possibly not saved your changes in
wiki.";
}
else
{
// alert('Did not find '+temp2);
}
}
</SCRIPT>
Then alter the body line, from:
<body <?php echo $message ? "onLoad=\"alert('".$message."');\" " : "" ?> >
To:
<body *onbeforeunload="AlertOnExit()"* <?php echo $message ?
"onLoad=\"alert('".$message."');\" " : "" ?> >
After uploading header.php to your server and refreshing your wiki page,
whenever you close or surf to another URL while a wiki page is being edited
you get a dialog asking whether you're sure.
It's my first encounter with javascript so I'm sure there is lots to be
improved :) hope somebody finds it usefull.
By the way, I got this working in Internet Explorer 6 and it worked for a
while in Firefox, then suddenly it broke... Still don't know why. If anyone
could me a pointer?
Cheers
Mick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.wikkawiki.org/pipermail/community_wikkawiki.org/attachments/20080521/58528f94/attachment.html
More information about the community
mailing list