JS Development memo notes - Javascript in document.execCommand () usage

When document.execCommand common syntax is as follows () method for processing data Html:
document.execCommand (sCommand [interactive mode, the dynamic parameter])

where: sCommand instruction parameters (for example the "2D-Position" below), the parameters interactively If true, then the dialog is displayed, if false, then the dialog is not displayed (in the embodiment of "false" means that no dialog is displayed), the dynamic parameters are generally available as a value or an attribute value (in the following example "true").

document.execCommand ( "2D-Position", "false", "true");

call execCommand () can achieve a lot of features, such as the browser menu to save the file, open a new file, undo, redo and so on ... there. this method, you can easily achieve the website text editor.

If flexible use, may well help us complete a variety of projects.

examples are as follows:

1. Select〗 〖order to achieve
[format]: document.execCommand ( "selectAll")
[Description] the entire content selection web page!
[For example] in between to join:
Select

2, open〗 〖order to achieve
[Format]: document.execCommand ( "Open")
[Description] This and other programming with VB design webbrowser control commands are somewhat similar, we so also pondering pondering.
[Examples] was added in between:
opening

3, Save As〗 〖order to achieve
[Format]: document.execCommand ( "saveAs")
[Description] Save the Web page to another directory on the local disk!
[For example] in between adding:
Save as

to achieve 4, 〖Print〗 command
[Format]: document.execCommand ( "Print")
[Description] Of course, you have to install the printer!
[For example] in between adding:
print

Js code listed below is the instruction parameters and significance

// equivalent to the Open button, click the file
document.execCommand ( "Open");

// save the current page as
document.execCommand ( "the SaveAs");

// Cut the selected text to the clipboard;
document.execCommand ( "Cut", "false", null);

// delete the selected text;
document.execCommand ( "the delete", "false", null);

// change the font of the selected area;
document.execCommand ( "FontName", "false", sFontName);

// change the font size of the selected area;
document.execCommand ( "the FontSize", "false", Ssize | iSize Number of );

// set the foreground color;
document.execCommand ( "the ForeColor", "false", sColor);

// make absolutely positioned objects can directly drag;
document.execCommand ( "the Position-2D", "to false", "to true");

// situating objects into absolute positioning;
document.execCommand ( "the AbsolutePosition", "to false", "to true");

// Set background color;
document.execCommand ( "the BackColor", "false", sColor);

// make text bold the selected area;
document.execCommand ( "Bold", "false", null);

// copy the selected text to the clipboard plate;
document.execCommand ( "the Copy", "to false", null);

// Sets the specified anchor bookmark;
document.execCommand ( "CreateBookmark", "to false", sAnchorName);

// the selected text into hyperlinks If the second parameter is true, the parameter setting dialog box appears;
document.execCommand ( "CreateLink", "to false", sLinkURL);

// set the label of a current block;
document.execCommand ( "FormatBlock", "to false ", sTagName);

// equivalent to the open button, click the file
document.execCommand (" open ");

// save the current page as
document.execCommand (" SaveAs ");

// Cut the selected text to the clipboard;
document.execCommand ( "Cut", "false", null);

// delete the selected text;
document.execCommand ( "the Delete", "false", null);

// change font selected area;
document.execCommand ( "FontName", "false", sFontName);

// change the font size of the selected area;
document.execCommand ( "the FontSize", "false", Ssize | iSize Number of);

// set the foreground color;
document.execCommand ( "the ForeColor", "to false", sColor);

// make the object can be absolutely positioned directly drag;
document.execCommand ( "the Position-2D", "to false", "to true");

// situating objects become absolute positioning;
document.execCommand ( "AbsolutePosition", "false", "to true");

// set the background color;
document.execCommand ( "the BackColor", "false", sColor);

// the selected bold text area;
document.execCommand ( "Bold", "false", null);

// copy the selected text to the clipboard;
document.execCommand ( "Copy", "false", null);

// set specify an anchor for the bookmark;
document.execCommand ( "CreateBookmark", "false", sAnchorName);

// will become the selected text hyperlinks, if the second argument is true, the parameter settings dialog box will appear;
document.execCommand ( "CreateLink", "false", sLinkURL);

// set the tag name of the current block;
document.execCommand ( "FormatBlock", "false", ; sTagName)

is useful when the document object execCommand normal processing Html data online in IE, it allows you to easily achieve the text bold, colors, fonts, etc. plus a series of commands.

D-Position allows movement of the object by dragging absolute positioning.
AbsolutePosition set of elements position property to "absolute" (absolute).
BackColor set or get the current background color of the selected area.
BlockDirLTR not currently supported.
BlockDirRTL not currently supported.
Bold switching current selection bolded or not.
BrowseMode not currently supported.
Copy Copy the current selected area to the clipboard.
CreateBookmark create a bookmark anchor or get the current selection or insertion point to the name of a bookmark anchor.
CreateLink insert a hyperlink on the current selection, or to display a dialog box allows the user to specify the URL you want to insert into the current selection a hyperlink.
Cut Copy the current selected area to the clipboard and delete it.
Delete Delete the current selection.
DirLTR not currently supported.
DirRTL not currently supported.
EditMode is not yet supported.
FontName Sets or retrieves the current font selected area.
FontSize Sets or retrieves the current font size of the selected area.
ForeColor Sets or retrieves the current selection of the foreground (text) color.
FormatBlock provided a current block formatting tags.
Indent increased the selected text indent.
InlineDirLTR not currently supported.
InlineDirRTL not currently supported.
InsertButton coverage area with the currently selected button controls.
InsertFieldset covered by the current selection box.
InsertHorizontalRule covering the current selection with the horizontal line.
InsertIFrame covering the current selection with the inline frame.
InsertImage image covering the current selection.
InsertInputButton coverage area with the currently selected button controls.
InsertInputCheckbox covering the current selection with a check box control.
InsertInputFileUpload covering the current selection with the file upload control.
InsertInputHidden insert a hidden control covering the current selection.
InsertInputImage covering the current selection image control.
InsertInputPassword covering the current selection with password control.
InsertInputRadio covering the current selection with the radio button controls.
InsertInputReset covering the current selection with a reset control.
InsertInputSubmit filed with the controls covering the current selection.
InsertInputText coverage area with the currently selected text control.
InsertMarquee covering the current selection empty subtitles.
InsertOrderedList switching the current selection list is the number of blocks or a regular format.
InsertParagraph wrap covered by the current selection.
InsertSelectDropdown covering the current selection with a drop-down box control.
InsertSelectListbox covered by the current selection list box control.
InsertTextArea covering the current selection with multi-line text input control.
InsertUnorderedList switching the current selection is a routine or bulleted list formatting block.
Italic switching current selection italics or not.
JustifyCenter where the current selection in the format block concatenation.
JustifyFull not currently supported.
The current selection JustifyLeft formatting block located left aligned.
JustifyNone not currently supported.
The current selection JustifyRight formatting block located right alignment.
LiveResize force MSHTML editor continually updated during zooming or moving elements of the appearance, not only in the pan or zoom the update is finished.
MultipleSelection allowed when the user holds down the Shift or Ctrl key to select more than one site once optional element.
Open not yet support.
Outdent reduce the selected area where the indented block format.
Switching between insert and overwrite text OverWrite state.
Paste covering the current selection with the contents of the clipboard.
PlayImage not currently supported.
Print to open the Print dialog box so the user can print the current page.
Redo is not yet supported.
Refresh Refresh current document.
RemoveFormat delete formatting tags from the currently selected area.
RemoveParaFormat not currently supported.
SaveAs Saves the current Web page as a file.
SelectAll select the entire document.
SizeToControl not currently supported.
SizeToControlHeight not currently supported.
SizeToControlWidth not currently supported.
Stop is not yet supported.
StopImage not currently supported.
StrikeThrough not currently supported.
Subscript not currently supported.
Superscript is not yet supported.
UnBookmark delete all bookmarks from the current selection area.
Underline switching current selection is displayed underlined or not.
Undo is not yet supported.
Unlink to delete all hyperlinks from the currently selected area.
Unselect clear the current selected selected area.

About document.execCommand:
To perform editing commands may invoke document.execCommand, and transmitting a command corresponding to the ID string. Another optional second parameter, which can be applied if it specifies whether the command user interface. Passing an integer of 1 to display a user interface, an integer of 0 to skip it. This parameter is not used for editing commands. Because the default value is 0, so if you do not use the third parameter (in this case, must also be passed to the second parameter value), regardless of it generally. The third parameter is optional, in the case of application, use it to pass any required parameters to the command.

Pixy method by IE bug affects the cache flashes. In fact, this problem is not clear, but the fact that the bug is conditional, that cache of IE is set to Every visit to the page, instead of the default Automatically. Basically, Only developers access to the cache is set to check each update, so this bug is not going to affect real users (according to ie6 under test in winxpsp2, although one might still call api network access, but the actual request did not happen, the symptoms of the mouse is a very short time jitter, but the image does not flicker). Furthermore, it was found a way to make an undisclosed IE cache of background:
document.execCommand ( "BackgroundImageCache", false, to true)

in this way even avoids the api calls, looks like a direct memory cache in IE.

Under IE6 set the background image will not be staying true cache, even if the servers do cache, cache if you want to live only ~ ~ ~

UI has done the design and development of people must know, IE (not including IE7) will often be reloaded background image from the server side, hey UI interface in IE (not including IE7) and it was the toss ......

Erik found a simple solution (for IE7 IE less effective, in fact, this has been fixed in IE7 Bug)
program code program code

document.execCommand ( "BackgroundImageCache", false, true);


today found reading Jack Slocum has Ext source considering this point, given Ext.js in his realization, in other Ajax frameworks should be no such similar code, a detail can be seen from this round - Ext
program code program code

var isIE ua.indexOf = ( "MSIE")> -1, isIE7 = ua.indexOf ( "MSIE. 7")> -1;
// Remove CSS Image Flicker
IF (! && isIE isIE7) {
the try {
document.execCommand ( "BackgroundImageCache ", false, to true);
} the catch (E) {}
}


today read magic Yu dreamplayer player source code found magic Yu also a fix for the IE cache background, but he did not take into account that does not exist in IE7 phenomenon This is evml.js in the section of the relevant code ~ (incidentally whispered a few words: this guy, never write JS semicolon, and never was, now or so, so how to compress it, in accordance with the following code Khan ~ I used to have with a semicolon, even if only twenty-three only ~)
program code program code

windows.isIE=navigator.appName.indexOf("Microsoft")==0;
if(isIE){
document.documentElement.addBehavior("#default#userdata");
document.execCommand("BackgroundImageCache",false,true);

Guess you like

Origin www.cnblogs.com/agoodlife/p/10931202.html