This article describes the method of JS to implement pasteHTML compatibility with ie, firefox, and chrome. Share it for your reference, as follows:
<html><body><script language="JavaScript">function test() { if (document.selection && document.selection.createRange) { var myRange = document.selection.createRange(); var m = myRange.pasteHTML('<iframe width=100 height=100 src="http://localhost/t2.htm"></iframe>'); } else if (window.getSelection) { var selection = window.getSelection(); var range = window.getSelection().getRangeAt(0); range.deleteContents(); var newP = document.createElement('iframe'); newP.src="http://localhost/t2.htm"; newP.width="100"; newP.height="100"; 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="test();"></body></html>For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques", and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.