Using this code for prevent accidentally closing survey alert come on access code screen only.
I want this alert when browser close.
$(document).on('ready pjax:scriptcomplete',function(){
/**
* Code included inside this will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute
* @see
learn.jquery.com/using-jquery-core/document-ready/
*/
});
//FEATURES: (2015-03-27) Now with fix for iframes (e.g. file uploader) and the template editor
function goodbye(e) {
if(!$('body', top.document).hasClass('submitted') && !$('#completed').length && !$('.templateeditor', top.document).length) { //check if a button was used to navigate OR the survey is completed OR the template is displayed in the template editor
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'Are you sure you want to quit this survey?'; //This is displayed on the dialog for IE
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
return 'Are you sure you want to quit this survey?'; // For chrome
}
}
window.onbeforeunload = goodbye;
$(document).on('click', '.button, .changelang, [name="move"]', function(event){ //added .changelang here, please add other classes if you know which should be allowed to navigate
$('body', top.document).addClass('submitted');
});
(window).on('beforeunload', function(){
var c=confirm();
if(c){
return true;
}
else
return false;
});