JS Execcommand Method

Source: Internet
Author: User

The document.exe ccommand () method uses the following syntax to process HTML data:
Copy content to clipboard
Code:
Document.exe ccommand (scommand [, interaction mode, dynamic parameters])

Scommand is the command parameter ("2d-position" in the following example). If the interaction mode parameter is true, the dialog box is displayed. If the interaction mode parameter is false, the dialog box is not displayed ("false" in the following example indicates that the dialog box is not displayed). A dynamic parameter is generally an available value or a property value ("true" in the following example ").

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

Execcommand () can be called to implement many functions of the browser menu, such as saving files, opening new files, undo and redo operations... And so on. With this method, you can easily implement the text editor in the webpage.

If it is used flexibly, it can help us complete various projects.

An example is as follows:

1. Implementation of the [select all] command
[Format]: document.exe ccommand ("selectall ")
[Description] All content on the webpage will be selected!
[Example] Add:
Select All

2. Implementation of the open command
[Format]: document.exe ccommand ("open ")
[Note] This is similar to the webbrowser control commands in programming design such as VB. You can also consider it here.
[Example] Add:
Open

3. Implementation of the "Save as" command
[Format]: document.exe ccommand ("saveas ")
[Note] Save the webpage to another directory on the local disk!
[Example] Add:
Save

4. Implementation of the *** print *** command
[Format]: document.exe ccommand ("print ")
[Note] Of course, you must have installed a printer!
[Example] Add:
Print

Command Parameters and meanings are listed below the JS Code

// It is equivalent to clicking the OPEN button in the file
Document.exe ccommand ("open ");

// Save the current page
Document.exe ccommand ("saveas ");

// Cut the selected text to the clipboard;
Document.exe ccommand ("cut", "false", null );

// Delete the selected text;
Document.exe ccommand ("delete", "false", null );

// Change the font of the selected area;
Document.exe ccommand ("fontname", "false", sfontname );

// Change the font size of the selected area;
Document.exe ccommand ("fontsize", "false", ssize | isize );

// Set the foreground color;
Document.exe ccommand ("forecolor", "false", scolor );

// Drag the absolutely positioned object directly;
Document.exe ccommand ("2d-position", "false", "true ");

// Turn object positioning into absolute positioning;
Document.exe ccommand ("absoluteposition", "false", "true ");

// Set the background color;
Document.exe ccommand ("backcolor", "false", scolor );

// Bold the text in the selected area;
Document.exe ccommand ("bold", "false", null );

// Copy the selected text to the clipboard;
Document.exe ccommand ("copy", "false", null );

// Set the specified anchor as a bookmarks;
Document.exe ccommand ("createbookmark", "false", sanchorname );

// Convert the selected text to hyperjoin. If the second parameter is true, the Parameter Setting dialog box is displayed;
Document.exe ccommand ("CreateLink", "false", slinkurl );

// Set the label name of the current block;
Document.exe ccommand ("formatblock", "false", stagname );

// It is equivalent to clicking the OPEN button in the file
Document.exe ccommand ("open ");

// Save the current page
Document.exe ccommand ("saveas ");

// Cut the selected text to the clipboard;
Document.exe ccommand ("cut", "false", null );

// Delete the selected text;
Document.exe ccommand ("delete", "false", null );

// Change the font of the selected area;
Document.exe ccommand ("fontname", "false", sfontname );

// Change the font size of the selected area;
Document.exe ccommand ("fontsize", "false", ssize | isize );

// Set the foreground color;
Document.exe ccommand ("forecolor", "false", scolor );

// Drag the absolutely positioned object directly;
Document.exe ccommand ("2d-position", "false", "true ");

// Turn object positioning into absolute positioning;
Document.exe ccommand ("absoluteposition", "false", "true ");

// Set the background color;
Document.exe ccommand ("backcolor", "false", scolor );

// Bold the text in the selected area;
Document.exe ccommand ("bold", "false", null );

// Copy the selected text to the clipboard;
Document.exe ccommand ("copy", "false", null );

// Set the specified anchor as a bookmarks;
Document.exe ccommand ("createbookmark", "false", sanchorname );

// Convert the selected text to hyperjoin. If the second parameter is true, the Parameter Setting dialog box is displayed;
Document.exe ccommand ("CreateLink", "false", slinkurl );

// Set the label name of the current block;
Document.exe ccommand ("formatblock", "false", stagname );

The Document Object Execcommand is usually very useful when processing HTML data online in IE. It allows you to easily implement a series of commands such as bold text, color, and font.

D-position allows you to move an absolute position object by dragging it.
Absoluteposition: Set the position attribute of the element to "absolute" (absolute ).
Set backcolor or obtain the background color of the selected area.
Blockdirltr is not currently supported.
Blockdirrtl is not currently supported.
Bold switches whether the selected area is in bold or not.
Browsemode is not currently supported.
COPY Copies the selected area to the clipboard.
Createbookmark: Create a bookmarks anchor to obtain the name of the bookmarks anchor of the selected area or insert point.
CreateLink inserts a hyperlink in the selected area or displays a dialog box that allows you to specify the URL of the hyperlink to be inserted for the selected area.
Cut: copy the selected area to the clipboard and delete it.
Delete deletes the selected area.
Dirltr is not currently supported.
Dirrtl is not currently supported.
Editmode is not supported currently.
Fontname: set or obtain the font of the selected area.
Fontsize: set or obtain the font size of the selected area.
Set or obtain the foreground (text) color of the selected area.
Formatblock sets the formatting label of the current block.
Indent increases the indentation of selected text.
Inlinedirltr is not currently supported.
Inlinedirrtl is not currently supported.
Insertbutton overwrites the selected area with a button control.
Insertfieldset overwrites the selected area with a box.
Inserthorizontalrule overwrites the selected area with a horizontal line.
Insertiframe overwrites the selected area with an embedded frame.
Insertimage overwrites the selected area with an image.
Insertinputbutton overwrites the selected area with a button control.
Insertinputcheckbox overwrites the selected area with the check box control.
Insertinputfileupload overwrites the selected area with the file upload control.
Insertinputhidden inserts a hidden control to overwrite the selected area.
Insertinputimage overwrites the selected area with an image control.
Insertinputpassword overwrites the selected zone with a password control.
Insertinputradio overwrites the selected area with a single-choice button control.
Insertinputreset overwrites the selected area with the Reset Control.
Insertinputsubmit overwrites the selected area with the submit control.
Insertinputtext overwrites the selected area with a text control.
Insertmarquee overwrites the selected area with empty subtitles.
Insertorderedlist: select the number list or regular formatting block for the selected area.
Insertparagraph overwrites the selected area with a line break.
Insertselectdropdown overwrites the selected area with the drop-down box control.
Insertselectlistbox overwrites the selected area with the list box control.
Inserttextarea overwrites the selected area with the multi-line text input control.
Insertunorderedlist switches whether the selected area is a project symbol list or a regular formatting block.
Italic switch to whether the selected area is displayed in italic or not.
Justifycenter: place the selected area in the formatting block.
Justifyfull is not currently supported.
Justifyleft: Align the formatting block of the selected area to the left.
Justifynone is not currently supported.
Justifyright: Right-aligned the formatting block of the selected area.
Liveresize forces the mshtml editor to continually update the appearance of Elements During Scaling or movement, instead of updating the elements only after moving or scaling.
Multipleselection allows you to select more than one optional site element at a time when you press shift or Ctrl.
Open is not yet supported.
Outdent reduces the indentation of the formatting block where the selected area is located.
Overwrite switches the insert and overwrite of the text status.
Paste overwrites the selected area with the clipboard content.
Playimage is not currently supported.
Print opens the Print dialog box so that you can print the current page.
Redo is not currently supported.
Refresh refresh the current document.
Removeformat deletes the format tag from the selected area.
Removeparaformat is not supported currently.
Saveas saves the current web page as a file.
Selectall: select the entire document.
Currently, sizetocontrol is not supported.
Currently, sizetocontrolheight is not supported.
Currently, sizetocontrolwidth is not supported.
Stop is not supported currently.
Stopimage is not currently supported.
Strikethrough is not currently supported.
Subscript is not currently supported.
Superscript is not currently supported.
Unbookmark deletes all bookmarks from the selected area.
Underline switches whether the underline of the selected area is displayed.
Undo is not currently supported.
Unlink deletes all hyperlinks from the selected area.
Unselect clears the selected status of the selected area.

About document.exe ccommand:
To run the edit command, you can call document.exe ccommand and pass the string corresponding to the command ID. In addition, there is an optional second parameter, which specifies whether to display the user interface of this command if it can be applied. If integer 1 is passed, the user interface is displayed. If integer 0 is passed, the user interface is skipped. This parameter is usually not used to edit commands. Because the default value is 0, if you do not use the third parameter (in this case, you must pass a value for the second parameter), you can ignore it. The third parameter is optional. You can use it to pass any required parameter to the command when it can be applied.

The Pixy method will flash when it is affected by the cache bug of IE. In fact, this problem is not clearly stated, but the bug is actually conditional, that is, the IE cache is set to every visit to the page, rather than the default automatically. Basically, only developers can set the cache to check for updates each time, so this bug does not affect real users (according to the test in IE6 of winxpsp2, although a network access API may still be called, there is no actual request. The symptom is that the mouse is shaking for a very short period of time, but the image will not flash ). In addition, an undisclosed method was found to allow IE to cache the background image:
Document.exe ccommand ("backgroundimagecache", false, true)

This method even avoids API calls, and seems to be directly cached in IE memory.

In IE6, background images are not actually cached. Even if the server has a cache, you can only ~~~

People who have done uidesign and Development know that IE (excluding IE7) will often reload background images from the server, and the UI of the good end will be on IE (excluding IE7) ......

Erik found a simple solution (effective for IE of IE7 or earlier, but this bug has been fixed in IE7)
Program code

Document.exe ccommand ("backgroundimagecache", false, true );

/**
* Update @ 2007-04-02
*/
When reading the ext source code today, Jack Slocum has taken this into account. JS provides its implementation. This kind of code should not be available in other Ajax frameworks. From this details, we can see that ext is comprehensive ~
Program code

VaR isie = UA. indexof ("MSIE")>-1, isie7 = UA. indexof ("MSIE 7")>-1;
// Remove CSS image flicker
If (isie &&! Isie7 ){
Try {
Document.exe ccommand ("backgroundimagecache", false, true );
} Catch (e ){}
}

/**
* Update @ 2007-04-10
*/
Today, when I read the source code of dreamplayer, I found that magic has fixed the background cache for IE, but he did not consider that IE7 does not exist. This is evml. A piece of related code in JS ~ (By the way, this guy never gives extra points for writing JavaScript code. It used to be like this. Now it's still like this. How can we compress it? Khan ~ The following code adds a semicolon according to my habits, even if there are only two or three sentences ~)
Program code

Window. isie = navigator. appname. indexof ("Microsoft") = 0;
If (isie ){
Document.doc umentelement. addbehavior ("# default # userdata ");
Document.exe ccommand ("backgroundimagecache", false, true );

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.