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。