If the user tries to print (using ctrl+p) without checking at least one checkbox on the page an error message gets prompted. On IE 11, I do see the error message but simultaneously the print window (popup) also appears. How can I prevent the print window?
$(window).bind('keydown', function (event) {
if (event.ctrlKey || event.metaKey) {
switch (String.fromCharCode(event.which).toLowerCase()) {
case 'p':
event.preventDefault();
//alert('ctrl+p');
printFunc();
break;
}
}
});
Also tried :
window.onbeforeprint = function () {
//alert('ctrl-p');
printFunc();
event.preventDefault();
return false;
};
Function:
function printFunc() {
var selectedListinsCount = selected_Listings.join('').split('').length;
if (selectedListinsCount < 1) {
if ($('#errmesg').length == 0) {
$('.messageCenter').append('<span id="errmesg" class ="errmesg"> <span class="messageIcon"></span><span>Please select at least one listing</span></span>');
}
$('.messageCenter').show();
return false;
}
else {
$('.errmesg').remove();
$('.messageCenter').hide();
}
}