2014-02-19 156 views
0

有點奇怪的問題,我非常願意接受,這是不可能的,但有沒有一種方法可以使用jQuery或普通的JavaScript來檢查設備是否有能力打印?檢查設備是否可以打印

我們目前在我們的文章頁面上有一個按鈕,允許用戶點擊以打印頁面。但是在一些Android設備上,「javascript:window.print();」函數不起作用。

我只是想知道是否有一種方法來執行檢查,看看設備是否支持這種方式?

+0

類似的問題定義:http://stackoverflow.com/questions/9268840/determine-whether-browser-supports-printing –

+0

可能不會發生。檢查此:http://stackoverflow.com/questions/12216551/detect-if-user-has-printing-capabilities –

+0

我懷疑它。另外,如何處理雲打印? – j08691

回答

2

您可以使用功能檢測這樣的:

if('print' in window){ 
    window.print(); 
} else { 
    alert("Printing is not supported on this device"); 
} 
1

基本上,JavaScript有沒有辦法知道,如果該設備可以打印。畢竟,這主要取決於它連接到打印機。但是你可以檢查功能window.print是這樣

if(typeof window.print == 'function') { 
    //at least the function is available 
}