Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

javascript - Determine whether browser supports printing

I think the answer to this is almost certainly "no", because I've done a little testing and searching around, but is there any trick to detect whether window.print() even might work from inside a page (i.e., from JavaScript)? I know that even on a desktop/laptop it's never going to be possible to know whether there's a printer configured on the system, for example, but at least the browser will put up a print dialog.

My Android phone has a window.print() function but it (unsurprisingly) doesn't do anything.

Again I'm asking mostly so there's a good question on the topic at SO :-)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The print() method is synchronous. This makes it possible to do the aftermath in order to decide wether a print dialog has been shown

var start = +new Date();
window.print();
var delta = + new Date() - start;
console.log(delta);
if (delta > 100) { console.log('It worked'); }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...