New method for local printing of browsers

Source: Internet
Author: User

Background

Recently in the development platform, which involves the function of the local printing, this function as a development platform for a common function, from the web search for some solutions and open source JS components, test results are not satisfied, most of the printed content is placed in an IFRAME, to print the contents of the IFRAME, The impact on the performance is relatively large, especially to print more than the case, and the effect may not be the same as the actual display, simply or to find a way to achieve it, and then I figured out another method of implementation, and everyone to share under, who has a better solution welcome communication

Ideas

Thought to say is also relatively simple, so-called partial printing is only a part of the printed page (if the entire page is printed without problems, direct window.print () on it), when the printing of other unwanted parts hidden, finished printing and then restore the display can be, But pay attention to hide do not use display:none style, if there is a placeholder hidden visibility:hidden;

On the Code


jquery is used, so add the jquery library in.

function PrintArea (id) {var box=$ ("#" +id);    var Pbox;    Pbox=box.parent ();        while (true) {Pbox.children (). addclass ("Print_hide");        Box.removeclass ("Print_hide");        Box.addclass ("Print_parent");        if (pbox.get (0). tagname== "BODY") {break;        } Box=pbox;    Pbox=pbox.parent (); } window.print ();}

Source code upload as Attachment

New method for local printing of browsers

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.