現在のページをリロードする前に、未保存のメールがある場合は使用を促すようにしています。保存されていない電子メールは、unsaved というハッシュに保存されます。スクリプトは CoffeeScript で書きました。
このコードを使用すると
window.onbeforeunload = () ->
return "Your emails are not saved. Click \"Save Email\" on any email to save them all. If you would like to discard your emails, just leave this page" if unsaved.count > 0
私が得るメッセージで私に促すのではなく:
function ( data, fn ) {
return arguments.length > 0 ?
this.on( name, null, data, fn ) :
this.trigger( name );
}
Are you sure you want to reload this page?
CoffeeScript は次のように翻訳されます。
window.onbeforeunload = function() {
if (unsaved.count > 0) {
return "Your emails are not saved. Click \"Save Email\" on any email to save them all. If you would like to discard your emails, just leave this page";
}
};
CoffeeScript が関数ではなく文字列を返すようにするにはどうすればよいですか?