2012年11月28日 星期三

Event Object 在不同瀏覽器上相容性的問題

在 IE 上是一個由一個 Global 的 Object 來儲存。
在 IE 以外的瀏覽器上 (W3C 定義) 則是 Event 發生的當下傳遞 Event Object (event) 給 Event Handler。

##
You can access the event object differently in different browsers:
  • The window.event property is supported by Internet Explorer, Opera, Google Chrome and Safari. It returns a reference to an event object that is filled based on the current event.
    In Internet Explorer, the event object always has the same members, regardless of the event, but only a part of them is filled based on the current event.
    In Opera, Google Chrome and Safari, the type of the event object depends on the event.
  • In Firefox, Opera, Google Chrome, Safari and Internet Explorer from version 9, when an event occurs, an event object is initialized and passed to the event handlers as the first parameter. The type of the event object depends on the current event.
    In Internet Explorer before version 9, an event object is passed to an event handler only if it is registered with the attachEvent method. If an event listener is registered with the attachEvent method, the passed event object is a copy of the window.event object in all Internet Explorer versions.

##

Reference:
http://dev.opera.com/articles/view/handling-events-with-javascript/#eventobjectreferences
http://help.dottoro.com/ljogqtqm.php

沒有留言:

張貼留言