简体   繁体   English

是否可以从一个网页中获取数据并生成另一个(要打印的网页)而不会受到服务器的干扰?

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

相关问题 如何等待网页完成工作后再在另一个网页上的iframe中显示 - How to wait for webpage to finish its work before showing it in an iframe on another web-page 如何在 Python 中使用 Selenium 从网页中获取数据? - How to get data from a web-page using Selenium in Python? 网页是否可以从另一个文件动态插入数据而无需服务器调用 - Is it possible for webpage to dynamically insert data from another file without needing a server call 使用消息重定向到另一个网页 [暂停] - Redirecting to another web-page with a message [on hold] 如何将用户重定向到另一个网页 - how to redirect User to another web-page 从 web 页面中提取数据并插入到另一个网页的 html 代码中 - Extracting data from a web page and inserting into html code of another webpage 从网页获取变量的名称? - Get the names of variables from a web-page? 将数据从一个网页传递到另一个网页 - Passing data from one web page to another 是否有可能使网页加载元素的百分比进步? - Is it possible to get web-page loading elements progress in percentage? 在不使用表单的情况下,使用javascript将来自服务器的数据从一页传递到另一页 - Passing data that is coming from a server, from one page to another in javascript without using forms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM