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