Javascript only manages objects. HTML DOM elements, including HTML5, are objects, we can classify them as follows:
- Window object with all events
- An IFRAME object as complete as Window (which is why it is used by Youtube)
- DOM objects that have only control events, click, mouseup, mouseDown ... as well as their own events (audio, video, DIV BLOCK), etc.
Creating JAVASCRIPT objects is a bit like Visual Basic or C ++.
Events are easy to manage, we can mix the events of smartphones and computers. To provide support for older SAFARI, IE browsers, simply avoid using specific keywords such as (LET, =>, or values ββin function parameters such as X = 1).
Event Management:
var mouseup = (!('ontouchstart' in document.documentElement))? 'mouseup':'touchend'; var winresize = (!('ontouchstart' in document.documentElement))? 'resize':'orientationchange'; var mouseover = (!('ontouchstart' in document.documentElement))? 'mouseover':'touchstart'; var mouseout = (!('ontouchstart' in document.documentElement))? 'mouseout':'touchend';
To ensure compatibility:
var Event_mouseup = function (e)( Code mouseup....... }; if(object.addEventListener){ object.addEventListener(mouseup,Event_mouseup,{passive:true}); //passive true not return event }else if(object.attachEvent){ object.attachEvent(mouseup,Event_mouseup); }else{ object['on'+mouseup]=Event_mouseup; };
The Window object works exactly the same.
Event loading is really special on the HTML page.
Objects that handle this event are objects that load data, such as IMG, VIDEO, AUDIO, etc.
In general, when an object has a load event, it also has a load event with an error.
To understand the DOM and the browser, you must compare it, for example, with a C ++ window.
Window ----------------------- event Load -------- Object 1 HTML DOM --------- event1 Object --------- event2 Object -------- Object 2 HTML DOM --------- event1 Object --------- event2 Object ---------------------- event unload Window