At last after trying hard I was able to build you a good sample code
that will run on both IE and Firefox
this is it.
<html>
<body>
<script language="JavaScript">
function function1() {
if (document.selection && document.selection.createRange) {
var myRange = document.selection.createRange();
var m = myRange.pasteHTML('<p>Hello World</p>');
}
else if (window.getSelection) {
var selection = window.getSelection();
var range = window.getSelection().getRangeAt(0);
range.deleteContents();
var repl=document.createTextNode('Hello World');
var newP = document.createElement('p');
newP.appendChild(repl);
range.insertNode(newP);
}
}
</script>
<p>Highlight a part of this text, then click button below</p>
<input id="myB" type="button" value="Click me" onclick="function1();">
</body>
</html>
On May 10, 8:40 am, Geevaa <govivasa...@gmail.com> wrote:
> Hi All,
> Try the example javascript given in this link in IE and Firefox.http://www.java2s.com/Code/JavaScript/Node-Operation/pasteHTMLExample...
> html>
> <body>
> <script language="JavaScript">
> function function1() {
> var myRange = document.selection.createRange();
> var m = myRange.pasteHTML('<p>Hello World</p>');}
> </script>
> <p>Highlight a part of this text, then click button below</p>
> <input id="myB" type="button" value="Click me" onclick="function1();">
> </body>
> </html>
> Its works only in IE and not in Firefox.
> Is there is any Firefox equivalent coding to achieve the same
> functionality which is working good in IE?
> Thanks in advance.