Event-compatible invocation (Ie,firefox,chrome)

Source: Internet
Author: User

These two days in contact with JQuery Easyui (http://jquery-easyui.wikidot.com/), when the call to Window.event found that Firefox in the call event some compatibility issues:

After the Firefox page call, its Windows.event object is undefined:

if (typeof (window.event) = = ' undefined ') alert (' Window.event is undefined. '); else alert (' window.event is defined. ');

The above code executes in Firefox with the result: "Window.event is undefined." Execution results in IE and chrome: "window.event is defined."

Calling the event in Firefox requires passing a parameter event in the calling method, but some actions in the jquery Easyui cannot pass custom parameters, such as Onchick (node) in the tree, which can only pass the node parameter. To solve this problem, the page needs to execute the following code when it loads, initializing an event to solve the problem:

function Loadevent () {if (!document.all) {window.constructor.prototype. __definegetter__ ("Event", function () {var func = Arguments.callee.caller; while (func!= null) {var arg0 = func.arguments[0]; if (arg0 && (arg0.constructor = = Event | | arg0.constructor = = MouseEvent)) {return arg0;} func = Func.caller; return null; }); } }

There are also different calling methods for obtaining the mouse current coordinates in Firefox:

menu_x = Event.x? Event.x:event.pagex; Menu_y = Event.y? Event.y:event.pagey;

In IE and chrome, you can get mouse coordinates using event.x and Event.y, and in Firefox you need to use Event.pagex and event.pagey to get them.

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.