[英]Is it possible to take data from one web-page and generate another(webpage to be printed) without any interference of server?
我正在尝试从HTML中获取数据并从该数据生成报告以进行打印,因为互联网连接不是持久的,因此重要的是仅在客户端(即Web浏览器)上生成打印格式的报告。
It is if the page with data supports CORS 包含数据的页面是否支持CORS
http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing
Otherwise you hit the browser security limitations. 否则,您将遇到浏览器安全限制。
If you do not control the page providing data it probably won't work. 如果您不控制提供数据的页面,则可能无法使用。
If the data in the original HTML is sufficiently regular that you can parse it with reliability, it is possible to write a browser-resident bookmarklet that will mangle the DOM in any way you choose; 如果原始HTML中的数据足够规则,可以可靠地对其进行解析,则可以编写一个驻留在浏览器中的书签 ,该书签将以您选择的任何方式处理DOM。 if you packed enough logic into the bookmarklet, you could even delete the original, keep the data, and create a completely new page with the data, rendering from templates. 如果将足够的逻辑打包到小书签中,则甚至可以删除原始逻辑,保留数据并使用数据创建一个全新的页面,并从模板进行渲染。
This is not, however, your basic Javascript app. 但是,这不是您的基本Javascript应用程序。 Bookmarklets are something of a Dark Art. 书签是一种黑暗艺术。
Generate BOTH the screen and print versions from the server at the same time. 同时生成屏幕和打印版本。 Enclose different parts in DIVs with class="NotOnPrint" for the screen-only stuff, class="NotOnScreen" for the print-only stuff, and nothing extra for items that should appear on both screen and print. 将DIV中的不同部分括起来,其中class =“ NotOnPrint”表示仅用于屏幕的内容,class =“ NotOnScreen”表示仅用于打印的内容,而对于应同时出现在屏幕和打印上的项目则没有多余的内容。 Then use this CSS: 然后使用以下CSS:
@media screen { .NotOnScreen { display: none; @media screen {.NotOnScreen {显示:无; } } @media print { .NotOnPrint { display: none; }} @media print {.NotOnPrint {display:none; } } }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.