javascript - onclick print destination url -
i have link on our invoices page.
the link, points print friendly url printing invoice.
the issue is, "onclick" print content of url. not sure if dooable without opening destination url first. ?
link: ( first method doesnt work because prints current url )
<li class="print"><a href="https://www.mysite.com.au/pdf/invoice_parse.html?id=<?=$r['invoice'];?>" onclick="window.print();return false">print invoice</a></li> essentially, want onclick of link, print destination url. without leaving page. suggestions please
when use window.print(), prints current window. open iframe , call window.print() inside of it.
you away hiding iframe giving position: absolute; left: -9999px.
javascript
assuming these links match on protocol, domain , host.
var printinvoice = function(url) { var iframe = document.createelement('iframe'), iframedocument; iframe.style.postion = 'absolute'; iframe.style.left = '-9999px'; iframe.src = url; document.body.appendchild(iframe); if ('contentwindow' in iframe) { iframedocument = iframe.contentwindow; } else { iframedocument = iframe.contentdocument; } var script = iframedocument.createelement('script'); script.type = 'text/javascript'; script.innerhtml = 'window.print();'; iframedocument.getelementsbytagname('head')[0].appendchild(script); } untested, should work :)
Comments
Post a Comment