Print the text of the selection (with the formatting specified in HTML)

Source: Internet
Author: User
Tags format
Print

Search the Internet "Print selected text", the result is nothing, so try to write a script in this respect.

   Print selected text, and include HTML format, but is not perfect, because I did not

Document.stylesheets This set of objects enumerates CSS such as its class,id. To take out its format, this is also to be improved on the one hand. In fact, the copied text pasted into FrontPage and other web editing software can also implement this function, but not the software to install the friends do not worry, you can follow the following methods to achieve. Hope reprint Friend Annotated Source: Weaving Dream Forum (hehe, as for the author who does not matter, piracy does not investigate!)

  Implementation method:

Open the registry, open the primary key hkcu\software\microsoft\internet Explorer\menuext, and create a new item: Print the text of the selection area. The default value in the right pane is changed to: D:\script\printSelection.htm.

Then, under D: Disk, create a new folder script, and create a new printselection.htm file in the script folder, which reads:

<script>
var yexj00=external.menuarguments.document;
var sel=external.menuarguments.document.selection.createrange ();
Sel.execcommand ("copy");
if (Yexj00.getelementbyid ("Nooneusethisspecialname") ==null) {
var m=yexj00.createelement ("IFRAME");
M.id= "Nooneusethisspecialname";
void (Yexj00.body.insertAdjacentElement ("BeforeEnd", m));
}
var s=yexj00.frames[' Nooneusethisspecialname '];
S.document.designmode= "on";
Dialog=external.menuarguments.confirm ("Are you sure you want to print the selected text?");
if (dialog) {
S.focus ();
void (S.document.execcommand ("SelectAll"));
void (S.document.execcommand ("Delete"));
void (S.document.execcommand ("Paste"));
void (S.document.execcommand ("Print"));
}
else{alert ("Operation canceled!");
</script>

At this point, you can open a page, select the text and pictures you want to print, right-click the text and pictures you just selected, select the Print Selection Text menu, pop-up the Prompt box, click OK, and start printing.



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.