
Executes a command on the current document, current selection, or the given range.
Syntax
Parameters
sCommand Required. String that specifies the command to execute. This command can be any of the command identifiers that can be executed in script. bUserInterface Optional. Boolean that specifies one of the following values.
- false
- Default. Do not display a user interface. Must be combined with vValue, if the command requires a value.
true- Display a user interface if the command supports one.
vValue Optional. Variant that specifies the string, number, or other value to assign. Possible values depend on the command.
Return Value
Returns true if the command is successful.
Remarks
Do not invoke the execCommand method until after the page loads.
The bUserInterface and vValue parameters might be required depending on the command being executed.
Example
The following example shows how to use the CreateLink constant as the sCommand of the execCommand method to allow the user to create a hyperlink from selected text. The scriptMicrosoft JScript then retrieves the specified URL and uses it to replace the selected text.
<script type="text/javascript"> function AddLink() { //identify selected text var sText = document.selection.createRange(); if (sText.text != "") { //create link document.execCommand("CreateLink"); //change the color to indicate success if (sText.parentElement().tagName == "A") { sText.execCommand("ForeColor",false,"#FF0033"); } } else { alert("Please select some text!"); } } </script> <p unselectable="on">Select any portion of the following blue text, such as "My favorite Web site". Click the button to turn the selected text into a link. </p> <p style="color= #3366CC">My favorite Web site is worth clicking on. Don't forget to check out my favorite music group!</p> <button onclick="AddLink()" unselectable="on">Click to add link</button>
Standards Information
There is no public standard that applies to this method.
Applies To
document, controlRange, TextRange, ControlRangeCollection Constructor, HTMLDocument Constructor, TextRange Constructor
See Also
The following code saves 1-of-2 sources depending on the composed content:
1. its intended composition-- if docobj.write-sText begins with '<PRE></PRE>'
2. its javascript opener (editer) document-- if write-sText begins with '<HTML>' (eg.)
eg.
docobj.write('<HTML>'+headstyles.outerHTML+composed.outerHTML);
docobj.execCommand('SaveAs',true,'subdoc'); // saves javascript opener
NB.
3. saveAs onUnload by Window closure (eg. alt-F4) may fail (directory gets a file of 0KB) ... User can-try save from Refresh (eg. F5) before closing Window, but can-fail.
(onUnload issue can be fixed with onBeforeUnload)
4. exception - drive full
Note that if a file is Saved in too little space, the file is not only truncated, its descriptor is corrupted: e.g. on a USB Flash drive, the size spec. may be 10KB off and notepad.exe will drop another 9KB in the middle of copy-in (as when attempting to repair the file).
__
[24 - July 2008] You [can] post specific questions [in] the MSDN Forums at http:/forums.microsoft.com/msdn. You [may] get a quick response.

- 7/9/2008
- Mr. Raymond Kenneth Petry
- 3/26/2010
- Mr. Raymond Kenneth Petry

- 2/10/2009
- Ian Ringrose

.gif)