を使用して、ウィンドウを閉じる前に終了する機能のためにが、私はあなたの助けが必要window.onbeforeunload
を待っている私が窓(IE 11)を閉じると、確認ボックスがポップアップし、私は[OK]ボタンをクリックしているようです関数は実行したいが、関数が終了する前にウィンドウを閉じる(レコードをDBに保存する)。ウィンドウを閉じる前に関数imts_save_changes()がDB操作を終了する機会を与えるように、コードをどのように変更できますか?ここで
は、マークアップです:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
</style>
<script type="text/javascript">
window.onbeforeunload = function() { return test() }
function test() {
if (confirm("would you like to run the last function before closing the window?")) {
imts_save_changes()
alert("record saved")
}
}
</script>
</head>
<body></body>
</html>
問題のコード:
window.onbeforeunload = function() { return test() }
function test() {
if (confirm("would you like to run the last function before closing the window?")) {
imts_save_changes()
alert("record saved")
}
}
ナビゲーションをキャンセルして、通常のメッセージでonbeforeunloadを使用するだけです。 – epascarello
Javascriptではウィンドウを閉じることができません。これはセキュリティ機能です。マルウェアは、ユーザーがダメージを与えるまでウィンドウを開いたままにするために使用されます。 – Barmar
@barmar HTAsはセキュリティについてあまり気にしません... – Teemu