XForms/离开时警告
外观
< XForms
将此代码添加到 global.js
<script type="text/javascript">
// adding a gmail style function to stop the user from moving away from the page..
function unloadMessage(){message = "This form has not yet been submitted to the database\nAll data will be lost."
return message;}
function setBunload(on){window.onbeforeunload = (on) ? unloadMessage : null;}
setBunload(true);
</script>
Mozilla 页面 [1]
IE 手册 [2]
将 xf:load 操作与 xforms-value-changed 事件结合使用,以调用包含 setBunload(true) 的“脏”函数。
同样,在提交中使用 load 操作来调用包含“setBunload(false)”的“干净”函数。
function dirty() {
setBunload(true);
}
function clean() {
setBunload(false);
}
This one goes in your "submission" element:
<xf:load resource="javascript:clean()" ev:event="xforms-submit-done"/>
and this
<xf:load resource="javascript:dirty()" ev:event="xforms-value-changed"/>
goes somewhere in the form - place it at the body-level to capture all change events, or nest it within a more appropriate container.
此示例取自 2007 年的 Alex Bleasdale。