kevi kevi
kevi kevi

Reputation: 167

javascript / jquery : close window on print cancel?

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"?

Upvotes: 1

Views: 10805

Answers (2)

cheeken
cheeken

Reputation: 34655

window.print() has no standards; its operation is a grab-bag from browser to browser. Futhermore, to my knowledge, in no browser implementation does it pass information back. You cannot determine how the user responded to the print dialog via JavaScript.

That said, it would seem the only point of the print-friendly page would be to print. Perhaps you can close the window after prompting to print, regardless of how the user responded?

Upvotes: 0

Ibrahim Azhar Armar
Ibrahim Azhar Armar

Reputation: 25745

window.close()

closes the current window

you can do like.

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

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

Upvotes: 1

Related Questions