TIPS: solve the problem that "FF cannot read outerHTML", ffouterhtml

Source: Internet
Author: User

TIPS: solve the problem that "FF cannot read outerHTML", ffouterhtml

The DOM attribute outerHTML can be used in IE, Opera, google Chorme, and other browsers, but Firefox does not support this attribute. Although this attribute is not commonly used, however, we still need to use some applications, so it is necessary to implement the outerHTML function under FF.

After reading some articles on the Internet, the most typical method should be throughDefineSetter,DefineGetterTo extend this attribute for the DOM attribute. The specific implementation is to traverse the attributes and subnodes of the read element, and then assemble the html string by yourself. For details, refer to this article: firefox does not have an outerHTML solution. In this article, outerHTML reads and writes are complete.

The method of assembling HTML strings to obtain outerHTML values is a bit troublesome. You can see a solution on the Internet, and the code is concise, it can also be used in various browsers. The principle is: Create a div element, and put the cloned object of the element to be read into this div, and read the childNode of this div. The sample code is as follows:

Document. createElement ("DIV "). appendChild (htmlNode. cloneNode (true )). parentNode. innerHTML) document. createElement ("DIV "). appendChild (htmlNode. cloneNode (true )). parentNode. innerHTML)

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.