はいまたはいいえを選択したかどうかに応じて、一連のコードを実行する JavaScript の確認メニューを作成することを検討しています。
今、私はそれをwindow.onbeforeunload
イベントで発生させたいのですが、個人が「はい」を押したときだけ、残りのコードを機能させたいと思っています。彼らが「いいえ」を押した場合、私はwindow.onbeforeunload
完全にキャンセルしたいと思います. それがまったく可能かどうか、そしてどのようにか疑問に思っています。これが私がこれまでに持っているものです。これが必要な理由は、スクリプトを実行すると、戻ったときにポップアップが表示されますが、誰かが留まるか去るかを選択する前に表示されるためです。このclick();
機能は、情報の消去を開始します。.click();
誰かがリターン時に「はい」を押した後、「はい」を押した場合にのみ起動したい。
var validNavigation = false;
function wireUpEvents() {
var dont_confirm_leave = 0;
var leave_message = document.getElementById("kioskform:broswerCloseSubmit");
var leave_safari = document.getElementById("kioskform:broswerCloseSafari");
function goodbye(e) {
if (!validNavigation) {
function disp_confirm()
{
var leaveMessage=confirm("Are you sure you want to leave")
if (leaveMessage==true)
{ if (dont_confirm_leave!==1) {
if(!e) e = window.event;
//for IE
e.cancelBubble = true;
e.returnValue = leave_message.click();
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
//return works for Chrome and Safari
leave_safari.click();
return '';
//add the code to delete the kiosk information here.
// this is what is to be done.
}
}
else
{
Alert("Returning to the page.")
}
}
window.onbeforeunload=goodbye;
// Attach the event keypress to exclude the F5 refresh
jQuery('document').bind('keypress', function(e) {
if (e.keyCode == 116){
validNavigation = true;
}
});
// Attach the event click for all links in the page
jQuery("a").bind("click", function() {
validNavigation = true;
});
// Attach the event submit for all forms in the page
jQuery("form").bind("submit", function() {
validNavigation = true;
});
// Attach the event click for all inputs in the page
jQuery("input[type=submit]").bind("click", function() {
validNavigation = true;
});
}
// Wire up the events as soon as the DOM tree is ready
jQuery(document).ready(function() {
wireUpEvents();
});