JS Implementation Method for pasteHTML Compatibility with ie firefox chrome

  • 2021-06-29 10:07:28
  • OfStack

This paper gives an example of how JS implements pasteHTML compatibility with ie, firefox, 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>

More readers interested in JavaScript-related content can view this site's topics: JavaScript Switching Special Effects and Techniques Summary, JavaScript Find Algorithmic Techniques Summary, JavaScript Animation Special Effects and Techniques Summary, JavaScript Errors and Debugging Techniques Summary, JavaScript Data Structure and Algorithmic Techniques Summary, etc.Summary of JavaScript Traversal Algorithms and Techniques and Summary of JavaScript Mathematical Operation Usage

I hope that the description in this paper will be helpful to everyone's JavaScript program design.


Related articles: