[英]How do I print different page using javascript/jQuery/ajax?
With following code it's showing the print dialog box and print the page successfully but how do i print a different page after click on this same button ? 使用以下代码,它显示打印对话框并成功打印页面,但如何在单击同一按钮后打印不同的页面? Different page name is : letterprint.php
不同的页面名称是: letterprint.php
<div class="below_movie_left" id="printableArea">
My printing contents
</div>
<input type="button" class="submit_button" onclick="printDiv('printableArea')" value="Print" style="float:right;" />
<script>
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
Is this possible with javascript / jQuery / Ajax method ? 使用javascript / jQuery / Ajax方法可以实现吗? how ?
怎么样 ?
If you already have the page you want to print, put that page in an hidden iframe and print the content of iframe 如果您已经有要打印的页面,请将该页面放在隐藏的iframe中并打印iframe的内容
<iframe src="letterprint.php" name="frame"></iframe>
<input type="button" onclick="frames['frame'].print()" value="printletter">
You can't really print another page; 你不能真正打印另一页; browsers just don't give Javascript that power.
浏览器只是不给Javascript那么强大。 However, what you can do is change the content of the page the user is on.
但是,您可以做的是更改用户所在页面的内容。
In short, you can use AJAX or an iframe to access the second page (letterprint.php), and then replace the contents of an element on your page with that page's contents. 简而言之,您可以使用AJAX或iframe访问第二页(letterprint.php),然后使用该页面的内容替换页面上元素的内容。 If you don't want it visible to the user, you can use a targeted stylesheet to make the new content only visible when printing.
如果您不希望用户看到它,则可以使用目标样式表使新内容仅在打印时可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.