Home >Web Front-end >JS Tutorial >Summary of js script code compatible with IE and FF (commonly used)_javascript skills

Summary of js script code compatible with IE and FF (commonly used)_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:14:37921browse

/*In the following, IE is used instead of Internet Explorer, and MF/FF is used instead of Mozzila Firefox */

//window.event
IE: There is a window.event object
FF: There is no window.event object. Event objects can be passed as arguments to functions. Such as onmousemove=doMouseMove(event)
Solution: var event = event || window.event;
example:

Copy code The code is as follows:

<script> <br>function test(event) { <br>var event = event || window.event; <br>//do Something <br>} <br></script>



//Current mouse coordinates
IE: event.x and event.y.
FF: event.pageX and event.pageY.
Common: Both have event.clientX and event.clientY properties.

//The current coordinates of the mouse (plus the distance the scroll bar has rolled)
IE: event.offsetX and event.offsetY.
FF: event.layerX and event.layerY.
Solution:
Copy code The code is as follows: