简体   繁体   English

如何使用javascript / jQuery / ajax打印不同的页面?

[英]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.

相关问题 如何使用CSS或JavaScript / jQuery在每个页面上打印标题 - How do I print a header on every page using CSS or JavaScript/jQuery 如何使用jQuery ajax在不同的主机上检索和显示html / asp / aspx页面? - How do I retrieve and display html/asp/aspx page on different host using jQuery ajax? 如何使用javascript打印页面并隐藏标题? - How do I print a page using javascript and hide headers? 如何使用jQuery / Javascript将变量发布到另一页? - How do I POST variables using jQuery / Javascript to another page? 如何在中打印pdf档案 <object> 使用javascript或jQuery或ajax标记 - How to print pdf portfolio in <object> tag using javascript or jQuery or ajax 如何使用 jQuery Ajax 成功在我的 html 上打印邮递员返回的 JSON 数组? - How do I print my postman returned JSON array on my html using jQuery Ajax success? 如何使用javascript / jQuery一次在不同页面中打印表格 - How to print tables in different pages at a time using javascript/Jquery 如何使用javascript或jquery在页面加载时打印pdf文件 - How to print a pdf file on page load, using javascript or jquery 如何使用AJAX打印PHP POST数据? (没有jQuery) - How can I print PHP POST data using AJAX? (no jQuery) 如何在 CSP 中使用“default-src 'none'”时使用 Jquery AJAX 加载页面 - How do I load page using Jquery AJAX while using 'default-src 'none'' in CSP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM