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