Is it possible to take data from one web-page and generate another (webpage to be printed) without any interference of server?
I am trying to take data from a HTML <form>
and generate a report from that data for printing, as the internet connection is not persistent, it is important report in print format is generated o开发者_开发问答n client side only i.e. a web-browser.
It is if the page with data supports CORS
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.
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. Then use this CSS:
@media screen { .NotOnScreen { display: none; } } @media print { .NotOnPrint { display: none; } }
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; 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. Bookmarklets are something of a Dark Art.
精彩评论