自定义谷歌云打印按钮功能

时间:2011-12-21 16:28:41

标签: google-cloud-print

目前我正在使用我的网站的Google 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 个答案:

答案 0 :(得分:1)

完全没问题...只需将onclick处理程序附加到打印按钮,或者使用jQuery绑定单击并调用函数来执行您的电子邮件。我用它在打印之前用Ajax创建一个文档:

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

简化版......未经测试但应该有效:)