Customize google cloud print button function

2019-08-04 09:05发布

Currently i am using the google cloudprint button for my site

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

I want to send an email when I hit the print button, is this possible?

1条回答
冷血范
2楼-- · 2019-08-04 09:19

No problem at all... just attach an onclick handler to the print button, or bind the click with jQuery and call a function to do your email. I used it to create a document with Ajax before it was printed:

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

Simplified version... not tested but should work :)

查看更多
登录 后发表回答