Comparison of methods for printing URLs using hidden frames

Source: Internet
Author: User
Tags object comparison window

Click on a button or link to print another page, that is, print a URL.

Page Add a LINK element This method is simpler, in fact, you can do a hidden frame on the page to implement, but more than the above method to be stupid

Here's an example of printing a URL using hidden frames:

function Printurl (URL) {
if (window.print && window.frames && window.frames.printerIframe) {
var html = ';
HTML + = ' html + + ' <body onload= ' parent.printframe (window.frames.urlToPrint); " > ';
html + + ' <iframe name= ' urltoprint ' src= ' + URL + ' ><\/iframe> ';
HTML + = ' <\/body><\/html> ';
var ifd = window.frames.printerIframe.document;
Ifd.open ();
Ifd.write (HTML);
Ifd.close ();
}
}
function Printframe (frame) {
if (frame.print) {
Frame.focus ();
Window.print (); Use Print for a page
}
}

Then look at a hidden frame using the print of the plugin
function Printurl (URL) {
if (window.print && window.frames && window.frames.printerIframe) {
var html = ';
HTML + = ' html + + ' <body onload= ' parent.printframe (window.frames.urlToPrint); " > ';
html = ' <object style= ' display:none ' id= ' oprintctl ' classid= ' clsid:ca03a5a8-9890-49be-ba4a-8c524eb06441 ' Codebase= "eprintdemo.cab#version=3,0,0,9" viewastext></object> ";
html + + ' <iframe name= ' urltoprint ' src= ' + URL + ' ><\/iframe> ';
HTML + = ' <\/body><\/html> ';
var ifd = window.frames.printerIframe.document;
Ifd.open ();
Ifd.write (HTML);
Ifd.close ();
}
}
function Printframe (frame) {
if (frame.print) {
Frame.focus ();
Window.frames.printerIframe.document.oPrintCtl.Preview ();
Window.frames.printerIframe.document.oPrintCtl.Print ();
Window.frames.printerIframe.document.oPrintCtl.Print (TRUE);
}
Use the plug-in preview, printing and other functions to achieve.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.