Pastes HTML text into the given text range, replacing any previous text and HTML elements in the range.
Syntax
object.pasteHTML(html)Standards information
There are no standards that apply here.
Parameters
- html [in]
-
Type: BSTR
String that specifies the HTML text to paste. The string can contain text and any combination of the HTML tags described in HTML Elements.
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Remarks
This method might alter the HTML text to make it fit the given text range. For example, pasting a table cell into a text range that does not contain a table might cause the method to insert a table element. For predictable results, paste only well-formed HTML text that fits within the given text range.
This method is accessible at run time. If elements are removed at run time, before the closing tag is parsed, areas of the document might not render.
This feature might not be available on non-Microsoft Win32 platforms.
This method fails only when used inappropriately to paste HTML into a TEXTAREA element in Microsoft Internet Explorer 5 and later.
Examples
This example uses the pasteHTML method to replace the current selection with a new paragraph.
<SCRIPT LANGUAGE="JScript">
var sel = document.selection;
if (sel!=null) {
var rng = sel.createRange();
if (rng!=null)
rng.pasteHTML("<P><B>Selection has been replaced.</B></P>");
}
</SCRIPT>
Send comments about this topic to Microsoft
Build date: 2/14/2012
var tempNode = document.getElementById("insertion");
range.moveToElementText(tempNode);
tempNode.removeNode();
[tfl 10 07 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at
http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
1) If you ever need to clear all the contents of your rich-edit text control, a simple way to do it would be by selecting the whole document (body or div) and then apply: textRange.pasteHTML("") , however (on IE7) this only clears the text between the tags, but not the tags themselves.
2) if you ever think of implementing the undo feature by using textRange.select() and textRange.pasteHTML(), may be you should think it twice, becuase textRange.select() may work fine, but textRange.pasteHTML() won't do anything except clearing the selection.
1. pasteHTML is incompatible with range.text=... which overwrites its node (ie. deleting).
2. pasteHTML(" ... ") suppresses the leading space, but not the trailing.
3. pasteHTML(" ... ") works-- but tends to revert in Saving File (depending...).
4. pasteHTML affects endpoint ranges despite duplicate (but with-content are not-affected).
5. pasteHTML can reach outside its specified text-range and enclose the whole in <P></P> (if it contains a <P> or <BR><BR>: probably an interaction with the keyboard-data-entry SHIFT/ENTER-<BR>/<P>-decision; The effect is, it pulls the outer-texts into its <P>'s).
6. Note also that it can include to do so....
7. Note that Drag-and-Drop does this too, but pasteHTML from the clipBoard deletes most html, but converting to <BR>/<P>.