Use the Web page code "intercept" function, print a section of the page definition area content

Source: Internet
Author: User
Tags definition query window domain name
Print | page | page

Before the user prints the content of the Web page, the general direct selection of IE print function on the line. Some Web pages also have the "Print this Document" link function, also referred to as "window.print ();", similar to the manual printing of the page.

In general, we use the page to print, are only interested in the main content on the page, some relevant advertising pictures, useless text information can be excluded. If you need to achieve this effect, it is certainly undesirable to use the above method. The last time I wrote a domain name query, the use of XML, while processing query feedback information is the method of interception, that is, only useful information to read. In fact, the so-called "thief program" is also the principle of the Internet. With this idea, I tried to "intercept" the page printing. Of course, it is also for the HTML source code of the Web page to operate, the method is as follows:

1. Add JavaScript to the page's code header:

<script language=javascript>
function Doprint () {
bdhtml=window.document.body.innerhtml;
Sprnstr= "<!--startprint-->";
Eprnstr= "<!--endprint-->";
Prnhtml=bdhtml.substr (Bdhtml.indexof (SPRNSTR) +17);
Prnhtml=prnhtml.substring (0,prnhtml.indexof (EPRNSTR));
window.document.body.innerhtml=prnhtml;
Window.print ();
}
</script>

2, in the text of the page plus <!--startprint--> and <!--endprint--> logo. It is appended to the HTML where the user needs to print the saved text.

3, the interception of content has been completed, now add a "print" Link: <a href= "javascript:;" > Print Tutorials </a>

Of course, this feature is not going to happen if the browser is printed directly by hand.

In this way, the effect is complete. I also only provided a thought, because the home is not installed printers, so did not try. If you find a problem in the actual use, hope to correct it.



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.