Fire Javascript Function When Ctrl+p Is Pressed
I need to destroy a jQueryUI tabs when somebody tries to print the page. I can't hide it with CSS as I need the data from these tabs. Can anyone help/point me in the right directio
Solution 1:
This might work:
@media print {
.ui-tabs-nav { display: none; }
.ui-tabs.ui-tabs-hide { display: block !important; }
}
This is another shot in the dark (i haven't tried it) but:
<scripttype="text/javascript">window.onbeforeprint = destroyTabs;
functiondestroyTabs(){
$('#tabs').tabs('destroy').tabs();
}
</script>
Solution 2:
There is no way to do this in JavaScript in a cross browser friendly way.
The onbeforeprint
and onafterprint
methods will only work in IE and Firefox 6+. You can combine them with window.matchMedia
to add support for Chrome 9+ and Safari 5.1+. I've written about how to implement this at http://tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/.
Solution 3:
$(document).keypress("p",function(e) {
if(e.ctrlKey)
alert("Ctrl+P was pressed!!");
});
Post a Comment for "Fire Javascript Function When Ctrl+p Is Pressed"