Customize google cloud print button function

此生再无相见时 提交于 2019-12-11 09:06:38

问题


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:


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



来源:https://stackoverflow.com/questions/8593065/customize-google-cloud-print-button-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!