브라우저 간 이벤트 객체

1450 단어 브라우저
    var EventUtil = {

        addHandler: function(elem,type,handler){

            if (elem.addEventListener) {

                    elem.addEventListener(type, handler, false);

            }else if(elem.attachEvent){

                    elem.attachEvent('on'+type,handler);

            }else{

                    elem["on"+type] = handler;

            }

        },

        removeHandler: function(elem,type,handler){

            if (elem.removeEventListener) {

                    elem.removeEventListener(type, handler, false);

            }else if(elem.attachEvent){

                    elem.detachEvent('on'+type,handler);

            }else{

                    elem["on"+type] = handler;

            }

        },

        getEvent: function(event){

                return event ? event : window.event;

        },

        getTarget: function(event){

                return event.target || event.srcElement;

        },

        preventDefault: function(e){

                if ( e && e.preventDefault ) 

                    e.preventDefault(); 

                else 

                    window.event.returnValue = false; 



                return false; 

        }

    };



EventUtil.addHandler(document.getElementById('iphone'),'click',function(e){





		alert("iPhone , , !");



        EventUtil.preventDefault(e);





});

좋은 웹페이지 즐겨찾기