Allow Firefox to support the window. Event attribute

Source: Internet
Author: User

As we all know, there are two ways to get event objects on a webpage. One is to access the window. Event attribute, and the other is the first parameter of the event function.

IE only supports window. event, Firefox only supports the form of parameters, while other mainstream browsers support both. Therefore, for compatibility with FF, it is generally written:

Function handle (e) {e = E | event ;...}

Although this can be run in most cases, there is a problem with embedded calls. For example, , although we can pass arguments [0] as a parameter, this is usually used here, because handle may be bound to multiple elements. Although there are some solutions, but after all it is troublesome, it is better to do a permanent solution for Firefox: add an event attribute (getter) to his window ):

If (is FF ..) {var $ e = function () {var c = $ E. caller; while (C. caller) C = C. caller; return C. arguments [0]}; _ definegetter _ ("Event", $ E );}

 

Every time Firefox accesses the event attribute, it will access the top-level function along the call stack, that is, the function that captures the event. The first parameter of this function is the event object. In this way, all browsers can use the event attribute, without code like e = E | event.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.