Usage of Document.execcommand () in JavaScript

Source: Internet
Author: User

The Document.execcommand () method handles HTML data often in the following syntax format:

Document.execcommand (scommand[, interactive mode, dynamic parameter])

Where:Scommand is the instruction parameter ("2d-position" in the following example ), if the interaction parameter is True, the dialog box is displayed, if False, the dialog box is not displayed ( "false" in the following example That is, the dialog box is not displayed), and the dynamic parameter is generally an available value or a property value ("True" in the following example ).

Document.execcommand ("2d-position", "false", "true");

Calling ExecCommand () can implement many features of the browser menu . such as saving a file , opening a new file , undoing, redo ... And so on . With this method , you can easily implement a text editor in a Web page .

If used flexibly , we can assist us to complete various projects .

Examples of use are as follows :

1. Implementation of the Select All command

[ format]:d ocument.execcommand ("SelectAll")

[Description ] will be the selection of all the contents of the page!

[ For example] to add between:

Select All

2. Implementation of the Open command

[ format]:d ocument.execcommand ("open")

[Note ] This is similar to the commands in the WebBrowser control in programming design such as VB , we can also follow this to ponder.

[ For example] to add between:

Open it

3. Implementation of the Save As command

[ format]:d ocument.execcommand ("SaveAs")

[Note ] Save this page to another directory on this site!

[ For example] to add between:

Save As

4, the implementation of the Print command

[ format]:d ocument.execcommand ("print")

[Description ] Of course, you have to install a printer!

[ For example] to add between:

Print

JS code is listed below the directive parameters and meaning

Equivalent to clicking the Open button in a file

Document.execcommand ("Open");

Save the current page as

Document.execcommand ("SaveAs");

Clip the selected text to the Clipboard ;

Document.execcommand ("Cut", "false", NULL);

Delete the selected text ;

Document.execcommand ("Delete", "false", NULL);

Changes the font of the selected area ;

Document.execcommand ("FontName", "false", sfontname);

Change the font size of the selected area ;

Document.execcommand ("FontSize", "false", ssize|isize);

Set the foreground color ;

Document.execcommand ("ForeColor", "false", scolor);

So that the absolutely positioned objects can be dragged directly ;

Document.execcommand ("2d-position", "false", "true");

Make the object positioning into absolute positioning ;

Document.execcommand ("AbsolutePosition", "false", "true");

Set the background color ;

Document.execcommand ("BackColor", "false", scolor);

Make the text in the selected area bold ;

Document.execcommand ("Bold", "false", NULL);

Copy the selected text to the Clipboard ;

Document.execcommand ("Copy", "false", NULL);

Sets the specified anchor point as a bookmark ;

Document.execcommand ("CreateBookMark", "false", sanchorname);

Changes the selected text to a hyperlink , and if the second argument is True, the Parameter Settings dialog box appears ;

Document.execcommand ("Createlink", "false", slinkurl);

Sets the label name of the current block ;

Document.execcommand ("Formatblock", "false", stagname);

Equivalent to clicking the Open button in a file

Document.execcommand ("Open");

Save the current page as

Document.execcommand ("SaveAs");

Clip the selected text to the Clipboard ;

Document.execcommand ("Cut", "false", NULL);

Delete the selected text ;

Document.execcommand ("Delete", "false", NULL);

Changes the font of the selected area ;

Document.execcommand ("FontName", "false", sfontname);

Change the font size of the selected area ;

Document.execcommand ("FontSize", "false", ssize|isize);

Set the foreground color ;

Document.execcommand ("ForeColor", "false", scolor);

So that the absolutely positioned objects can be dragged directly ;

Document.execcommand ("2d-position", "false", "true");

Make the object positioning into absolute positioning ;

Document.execcommand ("AbsolutePosition", "false", "true");

Set the background color ;

Document.execcommand ("BackColor", "false", scolor);

Make the text in the selected area bold ;

Document.execcommand ("Bold", "false", NULL);

Copy the selected text to the Clipboard ;

Document.execcommand ("Copy", "false", NULL);

Sets the specified anchor point as a bookmark ;

Document.execcommand ("CreateBookMark", "false", sanchorname);

Changes the selected text to a hyperlink , and if the second argument is True, the Parameter Settings dialog box appears ;

Document.execcommand ("Createlink", "false", slinkurl);

Sets the label name of the current block ;

Document.execcommand ("Formatblock", "false", stagname);

Document Object ExecCommand is often useful when working with HTML data online in IE, which allows you to easily implement a series of commands such as bold, color, and font text.

D-position allows an absolutely positioned object to be moved by dragging.

AbsolutePosition the position property of the Set element is "absolute" ( absolute).

BackColor Sets or gets the background color of the currently selected area.

Blockdirltr is not currently supported.

Blockdirrtl is not currently supported.

Bold toggles whether the current selection is displayed in bold or not.

Browsemode is not currently supported.

Copy copies the currently selected area to the Clipboard.

CreateBookMark creates a bookmark anchor or gets the name of the bookmark anchor for the current selection or insertion point.

Createlink inserts a hyperlink on the current selection, or displays a dialog box that allows the user to specify the URL of the hyperlink to be inserted for the current selection .

Cut copies the currently selected area to the Clipboard and deletes it.

Delete Deletes the currently selected area.

Dirltr is not currently supported.

Dirrtl is not currently supported.

EditMode is not currently supported.

FontName Sets or gets the font for the currently selected area.

FontSize Sets or gets the font size for the current selection.

ForeColor Sets or gets the foreground (text) Color of the currently selected area .

Formatblock Sets the current block formatting label.

Indent increases the indentation of the selected text.

Inlinedirltr is not currently supported.

Inlinedirrtl is not currently supported.

Insertbutton overrides the current selection with a button control.

InsertFieldSet overwrites the current selection with a box.

Inserthorizontalrule overwrites the current selection with a horizontal line.

Insertiframe overwrites the current selection with an inline frame.

Insertimage overwrites the current selection with an image.

Insertinputbutton overrides the current selection with a button control.

Insertinputcheckbox overwrites the current selection with a check box control.

Insertinputfileupload overwrites the current selection with a file upload control.

Insertinputhidden Inserts a hidden control that overrides the current selection.

Insertinputimage overwrites the current selection with an image control.

Insertinputpassword overwrites the current selection with a password control.

Insertinputradio overwrites the current selection with the radio button control.

Insertinputreset overrides the current selection with a reset control.

Insertinputsubmit overwrites the current selection with a Submit control.

Insertinputtext overwrites the current selection with a text control.

Insertmarquee overwrites the current selection with an empty caption.

Insertorderedlist Toggles whether the current selection is a numbered list or a regular formatting block.

InsertParagraph overwrites the currently selected area with a newline.

Insertselectdropdown overwrites the current selection with a drop-down box control.

Insertselectlistbox overwrites the current selection with a ListBox control.

Inserttextarea overwrites the current selection with the multiline text input control.

Insertunorderedlist Toggles whether the current selection is a bulleted list or a regular formatting block.

Italic Toggle the current selection italic display or not.

Justifycenter the current selection in the formatted block.

Justifyfull is not currently supported.

Justifyleft aligns the formatting blocks in the current selection to the left.

Justifynone is not currently supported.

Justifyright Right aligns the formatting blocks in the current selection.

Liveresize forces the MSHTML editor to continuously update the appearance of elements while zooming or moving, rather than just updating after the move or zoom is complete.

Multipleselection allows more than one site-selectable element to be selected at a time when the user holds down the shift or Ctrl key.

Open is not currently supported.

Outdent reduces the indentation of the formatting block where the selection is located.

OverWrite toggles the insertion and overwriting of text states.

Paste overwrites the current selection with the Clipboard contents.

Playimage is not currently supported.

Print opens the Printing dialog box so that the user can print the current page.

Redo is not currently supported.

Refresh refreshes the current document.

Removeformat removes the formatted label from the current selection.

Removeparaformat is not currently supported.

SaveAs Saves the current Web page as a file.

SelectAll Select the entire document.

SizeToControl is not currently supported.

SizeToControlHeight is not currently supported.

SizeToControlWidth is not currently supported.

Stop is not currently supported.

Stopimage is not currently supported.

Strikethrough is not currently supported.

Subscript is not currently supported.

Superscript is not currently supported.

Unbookmark removes all bookmarks from the current selection.

Underline toggles whether the underline of the current selection is displayed or not.

Undo is not currently supported.

Unlink removes all hyperlinks from the currently selected area.

Unselect clears the selected state of the current selection.

Usage of Document.execcommand () in JavaScript

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.