Dom prototype extension in Firefox

Source: Internet
Author: User
Tags cdata tagname
I don't want to provoke a debate between IE and Firefox. I just want to talk about the extensions of the object prototype in Dom that Firefox has but does not have in IE. In Dom, windows, document, element, event, and other objects have prototype corresponding to them in Firefox (or Mozilla core browser: window, htmldocument, htmlelement, event, etc. After these prototype extensions, objects such as window and document will "automatically" have certain Member attributes or member methods. For example, if IE has an outerhtml attribute, all the details of these elements can be obtained. However, this attribute is not a W3C standard attribute, therefore, non-ie browsers will not have this attribute. However, this attribute is very convenient to use. What should I do if I want to use this attribute in browsers such as Firefox? The prototype extension is used here: <SCRIPT type = "text/JavaScript">/* <! [CDATA [*/If (typeof (htmlelement )! = "Undefined "&&! Window. opera) {htmlelement. prototype. _ definegetter _ ("outerhtml", function () {var A = This. attributes, STR = "<" + this. tagname, I = 0; For (; I <. length; I ++) if (a [I]. specified) STR + = "" + A [I]. name + '= "' + A [I]. value + '"'; If (! This. canhavechildren) return STR + "/>"; return STR + ">" + this. innerhtml + "</" + this. tagname + ">" ;}); htmlelement. prototype. _ definesetter _ ("outerhtml", function (s) {var r = This. ownerdocument. createRange (); R. setstartbefore (this); var df = R. createcontextualfragment (s); this. parentnode. replaceChild (DF, this); Return s;}); htmlelement. prototype. _ definegetter _ ("canhavechildren", function () {return! /^ (Area | base | basefont | Col | frame | HR | IMG | BR | input | isindex | link | meta | PARAM) $ /. test (this. tagname. tolowercase ();}/*]> */</SCRIPT> after such a piece of code is added, the document is called in the Firefox browser. getelementbyid ("divid "). outerhtml, (Read/assign values) are all normal, this advantage is not available in IE series browsers. This is a highlight of Firefox (Mozilla's core browser! Below are two more useful extensions: <SCRIPT type = "text/JavaScript">/* <! [CDATA [*/If (! Window. attachevent & window. addeventlistener) {window. prototype. attachevent = htmldocument. prototype. attachevent = htmlelement. prototype. attachevent = function (EN, func, cancelbubble) {var cb = cancelbubble? True: false; this. addeventlistener (en. tolowercase (). substr (2), func, CB) ;}; window. prototype. detachevent = htmldocument. prototype. detachevent = htmlelement. prototype. detachevent = function (EN, func, cancelbubble) {var cb = cancelbubble? True: false; this. removeeventlistener (EN. tolowercase (). substr (2), func, CB) ;}}if (typeof event! = "Undefined "&&! Window. Opera) {var T = event. Prototype; T. _ definesetter _ ("returnvalue", function (B) {If (! B) This. preventdefault (); return B;}); T. _ definesetter _ ("cancelbubble", function (B) {If (B) This. stoppropagation (); return B ;}); T. _ definegetter _ ("offsetx", function () {return this. layerx;}); T. _ definegetter _ ("offsety", function () {return this. layery;}); T. _ definegetter _ ("srcelement", function () {var n1_this.tar get; while (N. nodetype! = 1) n = n. parentnode; return n ;});}/*]> */</SCRIPT> the above Code is intercepted by the jsframewrok framework I wrote.
View code


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