2011-12-21 100 views
1

目前我使用谷歌的CloudPrint中按鈕爲我的網站自定義谷歌雲打印按鈕功能

<script src="//www.google.com/cloudprint/client/cpgadget.js"></script> 
<script defer="defer"> 
    var gadget = new cloudprint.Gadget(); 
    gadget.setPrintButton(document.getElementById("custom_print_button")); 
    gadget.setPrintDocument("url", "Cloud Print test page", 
          "http://www.google.com/cloudprint/learn/"); 
</script> 

我想發送電子郵件時我打的打印按鈕,這可能嗎?

回答

1

完全沒有問題...只需將onclick處理程序附加到打印按鈕,或將點擊與jQuery綁定,然後調用函數來執行您的電子郵件。我用它來創建與阿賈克斯的文件就付印前:

<script> 
    function printIT() { 
     jQuery.ajax({ 
      url: "print_this.php", 
      context: document.body, 
      success: function(responseText) { 
       alert("Document sent!"); 
       return false; 
      } 
     }); 
    } 
</script> 

<button id="print_button_container" class="ui-link" onclick="printIT();"></button> 

<script src="//www.google.com/cloudprint/client/cpgadget.js"> 
</script> 
<script defer="defer"> 
    var gadget = new cloudprint.Gadget(); 
    gadget.setPrintButton(document.getElementById("print_button_container")); 
    gadget.setPrintDocument("url", "My Document", "http://www.yourpath.com/yourdoc.html"); 
</script> 

簡化版......沒有測試,但應該工作:)