网络编程
位置:首页>> 网络编程>> JavaScript>> JS实现pasteHTML兼容ie,firefox,chrome的方法

JS实现pasteHTML兼容ie,firefox,chrome的方法

作者:yiluoAK_47  发布时间:2023-09-21 01:55:10 

标签:JS,pasteHTML,兼容

本文实例讲述了JS实现pasteHTML兼容ie,firefox,chrome的方法。分享给大家供大家参考,具体如下:


<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>

希望本文所述对大家JavaScript程序设计有所帮助。

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com