sitelink1  
sitelink2  
sitelink3  
sitelink4 http://1 
extra_vars4 ko 
extra_vars5 http://arstechnica.com/civis/viewtopic.php?f=20&t=185317 
extra_vars6 sitelink1 

Question

Object.prototype.removeNodes = function() {
    var node = this;
    while (this.lastChild) node.removeChild(this.lastChild);
}
The purpose of this prototype is to remove all children from an element. It works fine in Gecko, WebKit/KHTML, and Opera. But not IE.


IE does not support prototype extensions of HTML elements.

So you have to fake it instead with something like...


http://www.geekdaily.net/2007/06/18/javascript-htmlelement-in-ie/
or
http://delete.me.uk/2004/09/ieproto.html
or maybe
http://www.browserland.org/scripts/htmlelement/



결론은


Element = function () {};


Element.prototype.getAttribute = function (attribute) {

    if (attribute == "class") attribute = "className";

    if (attribute == "for") attribute = "htmlFor";

    return this[attribute];

}


Element.prototype.setAttribute = function (attribute, value) {

    if (attribute == "class") attribute = "className";

    if (attribute == "for") attribute = "htmlFor";

    this[attribute] = value;

}



------------------------------------------------------------------------------------

createElement 재정의 방법1


var __IEcreateElement = document.createElement;


document.createElement = function (tagName) {

    var element = __IEcreateElement(tagName);


    var interface = new Element;

    for (method in interface)

        element[method] = interface[method];


    return element;

}


------------------------------------------------------------------------------------

createElement 재정의 방법2


document.createElement = (function(fn){

    return function(tagName){

        var elem = fn.call(document, tagName);

        elem.$ = function(){

            alert(arguments[0])

        }

        return elem;

    };

})(document.createElement);


------------------------------------------------------------------------------------

createElement 재정의 방법3 (추천)


document._createElement = document.createElement; 

document.createElement = function(tag)

{

    var el=document._createElement(tag);


    el.methodYouWantToAdd = function(args) {

        //do stuff with "this"

        return this; 

    }


    return el;

}


------------------------------------------------------------------------------------


번호 제목 글쓴이 날짜 조회 수
197 XMLHttpRequest.timeout 황제낙엽 2018.11.03 248
196 IFrames and cross-domain security file 황제낙엽 2012.01.13 246
195 UTF-8 한글 초성 추출 (자바스크립트) 황제낙엽 2019.05.07 243
» Why does this simple Javascript prototype not work in IE? 황제낙엽 2011.03.24 242
193 Function.apply and Function.call in JavaScript 황제낙엽 2011.10.07 238
192 브라우저에서 뒤로 가기 막기와 펑션키(function key) 막기 황제낙엽 2005.10.21 236
191 두 서버의 자원을 접근하는 클라이언트 프레임웍(Next.js)에서의 CORS오류 file 황제낙엽 2021.12.05 231
190 JavaScript Closures for Dummies 황제낙엽 2009.04.08 227
189 Javascript ArrayBuffer ? Binary handling in javascript 황제낙엽 2012.03.19 218
188 javascript array contains method 황제낙엽 2011.08.19 210
187 char to hex string 황제낙엽 2011.11.29 206
186 How to use Rhino to script Java classes. 황제낙엽 2008.07.14 199
185 Page Refresh/Reload 황제낙엽 2007.08.24 197
184 [펌] 아사페릴의 사생활 - Code Conventions for the JavaScript Programming Language 황제낙엽 2009.04.02 194
183 Reference Count (순환참조) 황제낙엽 2011.11.24 191
182 JavaScript Form Validation file 황제낙엽 2008.11.24 186
181 code compressor & decompressor 황제낙엽 2015.01.02 181
180 자바스크립트의 데이터 타입과 변수 황제낙엽 2008.08.06 179
179 SelectBox 밑에 CheckBox가 포함된 리스트 만들기 file 황제낙엽 2007.01.16 178
178 서비스 워커 file 황제낙엽 2020.05.25 177