execCommand method in javascript

Posted by in JavaScript category on for Beginner level | Views : 25627 red flag

This article explains the use of execCommand method used in Javascript that is used to execute a command in JavaScript.

 Download source code for execCommand method in javascript


if you are going to design a RichTextBox on your own, then go through execCommand method. It will execute a command on the current document or  the selected range in the document.


You can allow the user to paste the text from the clipboard using ‘Paste’ command in the execCommand method.

var myRange1 = document.body.createTextRange();



After pasting the data, if you want to delete selected data.Then use ‘Delete’ command in the execCommand method

var cRange = document.selection.createRange();


If the pasted data is bulletlist and if your want to indent the data then use ‘Indent’ command , if you want to outdent then use ‘Outdent’ command.

var cRange = document.selection.createRange();


var cRange = document.selection.createRange();



execCommand will be used to execute the command for the Current Range, Selected document.


Like this lots of commands can be used in the execute command, you can have a look at this post http://msdn.microsoft.com/en-us/library/ms533049(v=VS.85).aspx

Please download the Zip and execute the HTML. Select the bulletlist and click paste.

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Rajkumar Pauldurai
Member Level: Starter
Member Status: Member
Member Since: 5/26/2009 6:29:52 AM

I started my career with Asp,ms-access,sql server 7,xml.Then i updated to .net,share point server,Basics about Biztalk server

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)