javascript / jquery : close window on print cancel?

kevi kevi picture kevi kevi · May 13, 2012 · Viewed 10.1k times · Source

I'm generating a printer-friendly page that automatically opens the browser's print dialog box upon user visit. Is there a way to close the window if the user presses "Cancel"?

Answer

Ibrahim Azhar Armar picture Ibrahim Azhar Armar · May 13, 2012
window.close()

closes the current window

you can do like.

<button type="button" id="cancelButton">Cancel</button>

$('#cancelButton').click(function(){
    window.close();
});