beatovich: Frage zum Wiki-Artikel „Pointer Events“, Nachbesserung

Beitrag lesen

problematische Seite

hallo

So diesmal eine getestete Version

var eventSupport={
   'pointerdown': ('onpointerdown' in window)? true : false,
   'mousedown': ('onmousedown' in window)? true : false,
   // ...
};
//console.log(eventSupport);
function pickEvent(chooseFrom){
   while(chooseFrom.length > 0){
      var type = chooseFrom.shift();
      if(eventSupport[type] == true ) return type;
   }
}

// später
var el = document.body;
//console.log(el);
//console.log(pickEvent(["pointerdown","mousedown"]));
el.addEventListener(pickEvent(["pointerdown","mousedown"]), 
                    function(ev){console.log(ev);} 
);