admin管理员组文章数量:1389833
I'd like a "print" button on my web-site to print a document with Google Cloud Print, but I want the "url" of the target – a PDF file – to change dynamically, after the button has been clicked (notably, based on what's returned from an AJAX call).
The GCP Web Element (GCPWE) seems to have similar functionality, but not quite what I desire. In particular, it seems as though one can only change the "target" (by calling setPrintDocument
) before the button is clicked.
Is there a way to specify the URL for GCPWE after the button has been clicked?
Here's the example code from the GCPWE site:
<div id="print_button_container"> </div>
<script src=".js">
</script>
<script defer="defer">
var gadget = new cloudprint.Gadget();
gadget.setPrintButton(
cloudprint.Gadget.createDefaultPrintButton("print_button_container"));
gadget.setPrintDocument("url", "[document title]", "[document URL]");
</script>
I've considered hiding the <div id='print_button_container'>
and triggering a .click
event on it after a visible print button has been clicked, but this seems rather inelegant & improper. I've looked at the gpwidget.js
linked to above, but the code has been minimized and is unintelligible (to me, at any rate).
What I seem to desire is a Javascript print
function that you pass a [document URL] and [document title] to.
Is there a better way to achieve the desired functionality, rather than the 'clicking the hidden button' I've e up with?
Thank you for reading.
I'd like a "print" button on my web-site to print a document with Google Cloud Print, but I want the "url" of the target – a PDF file – to change dynamically, after the button has been clicked (notably, based on what's returned from an AJAX call).
The GCP Web Element (GCPWE) seems to have similar functionality, but not quite what I desire. In particular, it seems as though one can only change the "target" (by calling setPrintDocument
) before the button is clicked.
Is there a way to specify the URL for GCPWE after the button has been clicked?
Here's the example code from the GCPWE site:
<div id="print_button_container"> </div>
<script src="http://www.google./cloudprint/client/cpgadget.js">
</script>
<script defer="defer">
var gadget = new cloudprint.Gadget();
gadget.setPrintButton(
cloudprint.Gadget.createDefaultPrintButton("print_button_container"));
gadget.setPrintDocument("url", "[document title]", "[document URL]");
</script>
I've considered hiding the <div id='print_button_container'>
and triggering a .click
event on it after a visible print button has been clicked, but this seems rather inelegant & improper. I've looked at the gpwidget.js
linked to above, but the code has been minimized and is unintelligible (to me, at any rate).
What I seem to desire is a Javascript print
function that you pass a [document URL] and [document title] to.
Is there a better way to achieve the desired functionality, rather than the 'clicking the hidden button' I've e up with?
Thank you for reading.
Share Improve this question edited Oct 24, 2011 at 19:02 Brian M. Hunt asked Oct 24, 2011 at 18:31 Brian M. HuntBrian M. Hunt 83.9k76 gold badges234 silver badges349 bronze badges 1- Here's what I was able to do with the answer below... see this thread: stackoverflow./questions/8593065/… – Thomas Butler Commented May 22, 2012 at 18:23
2 Answers
Reset to default 4You can open print dialog whenever you want that, just call:
gadget.openPrintDialog()
and that will open printer dialog. So for your case you might want to create print button using static method:
cloudprint.Gadget.createDefaultPrintButton("print_button_container");
then attach custom handlers for the button, and whenever you are ready just call:
var gadget = new cloudprint.Gadget();
gadget.setPrintDocument(...);
gadget.openPrintDialog();
You can call method gadget.setPrintDocument() at any moment, even after the print dialog has been opened.
本文标签: javascriptPrint to Google Cloud Print with dynamic URLStack Overflow
版权声明:本文标题:javascript - Print to Google Cloud Print with dynamic URL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744603999a2615241.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论