JS-implemented pasteHTML-compatible ie, firefox, chrome methods, pastehtmlchrome

Source: Internet
Author: User

JS-implemented pasteHTML-compatible ie, firefox, chrome methods, pastehtmlchrome

This article describes how to implement pasteHTML compatibility with ie, firefox, and chrome in JS. We will share this with you for your reference. The details are 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>  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.