2015-12-14 51 views
1

我已經按照Getting the source HTML of the current page from Chrome extension從當前頁面獲取HTML源代碼,我修改了chrome.runtime.onMessage.addListener功能是這樣的:如何在chrome擴展中使用window.print()?

chrome.runtime.onMessage.addListener(function(request, sender) { 
    if (request.action == "getSource") { 
     message.innerText = request.source; 
     //my code 
     window.print(); 
    } 
}); 

window.print()不起作用,你可以請幫我糾正嗎?

非常感謝您提供任何幫助!

+0

在該文件中,你調用打印?它必須位於內容腳本中,而不是後臺任務。 – sdgluck

回答

0

您的代碼被反轉打印。 更改 「print.window()」 於以下內容:

window.print(); 
+0

謝謝,但還是不行,:( –

-1

你需要調用打印之前超時。

您可以使用的代碼片段作爲解決方法: window.print(); setTimeout(function(){window.close();}, 10000); //give them 10 seconds to print, then close

供您參考,請點擊以下鏈接: Print function in Chrome no longer working